Friday, June 20, 2025
HomeInterview ExperienceSalesforce Trigger Scenario Based Interview Questions

Salesforce Trigger Scenario Based Interview Questions

Telegram Group Join Now
whatsApp Channel Join Now
4.8/5 - (6 votes)

Salesforce Trigger Scenario Based Interview Questions | Salesforce Interview Questions on Triggers: If you are looking for Apex trigger Interview Questions scenario based then you are on the right page here we cover most asked Scenario based trigger Interview questions and answers for Experienced. Which was asked in TCS, Infosys, Deloitte, Capgemini and Accenture Company.

If you’re a Salesforce developer preparing for an interview, be sure to practice these questions and bookmark this page to keep it handy!

Trigger Scenario 1 : TCS trigger interview questions

When ever a case is created with origin as email then set status as new and Priority as Medium.

  • Object : Case
  • Trigger: Before Insert

Answer:

trigger CaseOrigin on Case (before insert) {
 for(case c : trigger.new){
  if(c.origin == 'Email'){
           c.status = 'New';
           c.priority = 'Medium';
          }
      }
}

Trigger Scenario 2 : Infosys trigger interview questions for experienced

When ever Lead is created with LeadSource as Web then give rating as cold otherwise hot.

  • Object : Lead
  • Trigger: Before Insert

Answer:

trigger LeadScenario on Lead (before insert) {
for(lead ld : trigger.new){
if(ld.leadsource == 'Web')
  {
   ld.Rating = 'Cold';
  }
else{
ld.Rating = 'Hot';
    }
  }
}

Trigger Scenario 3 : Accenture trigger interview questions

Whenever New Account Record is created then needs to create associated Contact Record automatically.

Object : Account
Trigger: After Insert

Description: When ever new Account record is successfully created, then create the corresponding contact record for the account with:

•account name as contact lastname
•account phone as contact phone

Answer:

trigger AccountAfter on Account (after insert) {
List<contact> cons=new List<contact>();
      for(Account acc: Trigger.New){
            Contact c=new Contact();
            c.accountid=acc.id;
            c.lastname=acc.name;
            c.phone=acc.phone;
            cons.add(c)
           }
   insert cons;
}

Test Class: Apex Code

@isTest
private class AccountAfterHandler {
@isTest
static void testme(){
Integer count=[select count() from Account];
Integer size=[select count() from Contact];
Account acc=new Account(Name='LearnFrenzy',phone='022-845454');
      try{
         insert acc;
         }
      catch(Exception e){
         System.debug(e);
        }
Integer newCount=[select count() from Account];
Integer newsize=[select count() from Contact];
Contact c=[select lastname,phone from Contact where accountid=:acc.id];
System.assertEquals(c.lastname,acc.name);
System.assertEquals(c.phone,acc.phone);
   }

Trigger Scenario 4 : Capgemini trigger interview questions

When ever the Account is created with Industry as Banking then create a contact for account, Contact Lastname as Account name and contact phone as account phone.

  • Object : Account
  • Trigger: After Insert

Answer:

trigger CreateAccountContact on Account (after insert) {
list<contact> contacts = new list<contact>();
    for(account acc : trigger.new){
        if(acc.Industry == 'Banking'){
             contact con = new contact();
             con.LastName = acc.name;
             con.Phone = acc.Phone;
             con.AccountId = acc.Id;
             contacts.add(con);
         }
      }
insert contacts;
}

Trigger Scenario 5 : Deloitte salesforce trigger interview questions and answers

Creates the number of contacts which are equal to the number which we will enter in the Number of Locations field on the Account Object.

Create Custom field called “Number of Locations” on the Account Object (Data Type=Number)

Object : Account
Trigger: After Insert

Answer:

trigger ContactsCreation on Account (after insert) {
list<contact> listContact = new list<contact>();
map<id,decimal> mapAcc = new map<id,decimal>();
  for(Account acc:trigger.new){
      mapAcc.put(acc.id,acc.NumberofLocations__c);
     }
        if(mapAcc.size()>0 && mapAcc!=null){
            for(Id accId:mapAcc.keyset()){
               for(integer i=0;i<mapAcc.get(accId);i++){
                 contact newContact=new contact();
                 newContact.accountid=accId;
                 newContact.lastname='contact'+i;
                 listContact.add(newContact);
                 }
              }
         }
if(listContact.size()>0 && listContact!=null)
insert listContact;
}

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments