Salesforce Interview Questions on Triggers

Jagdish Dhus
0

Salesforce Interview Questions on Triggers -


  1. What is Trigger in Salesforce?

Ans -     a. Trigger is a piece of code that executes before and after a record is inserted or updated.

      b. By using Trigger, we can perform all the DML operations on the same or other objects.

      c. By using Trigger, we can perform or implements the complex validation rules, complex 

  business logic.


2. What are the Two types of Triggers in Salesforce?

Ans-  a. Before Triggers - These Triggers will get fired 'Before' performing the operations on the object.

  b. After Triggers - These Triggers will get fired 'after' performing the operations on the object.


3. What are different Events Available in Triggers?

Ans-     a. Before insert

            b. Before Update

            c. Before Delete

            d. After Insert

           e. After Update

        f. After Delete

            g. After Undelete


4. Best Practices Triggers?

Ans -    a. One Trigger per object

    b. Less code Trigger

    c. always Bulkify code

    d. avoid SOQL or DML inside for loop

    e. always avoid hardcoding IDs


5. How many times does Trigger execute on an Upsert Event?

Ans- 4 times, before insert, before update, after insert, after update.


6. What is the difference between Trigger.New and Trigger.NewMap?

Ans- Trigger.New - It holds the Newly inserted records into the collection.(SObject)

Trigger.NewMap - It holds the Newly inserted records in Map format(ID, SObject)


7. When we should use Trigger.Old?

Ans- Trigger.Old is used to check the old value of the record. It can help you to stop recursion in Trigger.


8. What are Context Variables in Triggers?

Ans- With the help of Trigger Context Variables, we can Segregate the code blocks.

Apex provides the below Trigger Context Variables- 

    a. Trigger.isInsert

    b.Trigger.isUpdate

    c.Trigger.isDelete

    d.Trigger.isUndelete

    e.Trigger.isBefore

    f.Trigger.isAfter

    g. Trigger.New

    h. Trigger.Old

    i. Trigger.NewMap

    j. Trigger.OldMap

    k. Trigger.size


9. Can a trigger Call a Batch Class?

Ans- Yes.


10. What is Recursive Trigger?

Ans- If Trigger has the same DML statement and the same DML condition is used in the trigger firing condition on the same object.


11. What is Trigger.isExecuting?

Ans - Trigger.isExecuting is used to check method is getting called from the Trigger.


Post a Comment

0Comments
Post a Comment (0)
To Top