Part 6: Salesforce Interview Questions(Trigger)

51. If i have two triggers(Accttrigger and accounttrigger) on the Same object(Account) with Same event(after insert), can i know which trigger will fire first?

No we cannot determine which trigger can be fired first. In order to control the execution, write a trigger per object and call an Apex class where we can control the Execution.

52. Can we Call a Future method from trigger?

Yes we can call a future method from trigger. This feature is helpful to call a Webservice /Callout process.

53. Can we invoke a Schedule Job from Trigger?

We can invoke a Schedule job from Trigger.

54. Can we invoke a Batch Apex class from Trigger?

We can invoke a Batch Class from Trigger

trigger acctTrigger on Account(before insert,before update){

AccountBatch accBatch = new AccountBatch();



55. Can we Skip triggers for desired users or profiles in Salesforce?

We can skip triggers using Hierarchical Custom settings in salesforce for Desired profile.

56. When should we use before trigger vs after trigger?

As a groundrule, always use before triggers when you donot want to act on the Id of the record.Since before triggers doesnot require any DML it also helps in reducing DML and increasing performance compared to After Triggers. Use After triggers if we want to perform operations after the record is inserted(example Id is generated) and we want to perform operations on the child entities based on the record inserted. Ex: If we want to insert a contact record after an account is inserted then we need to write an After insert trigger on Account object and based on the account id we will insert the contact and associate Account id to it.

57.  Can we send Emails using Triggers?

Yes, We can send Emails using Triggers.The maximum number of Emails that could be sent is 5000 per org depending on Edition(Enterprise/Unlimited).

58. What are best practices in triggers?

a.Always write one trigger per object with all events.

b.For controlled execution write a trigger and call a Class and define methods in desired order.

c.Always write trigger to process a minimum of 200 records in single transaction

d. Avoid SOQL queries inside for loop as it will result in Governor Limits.

e. Avoid DML statements inside for Loop as it will result in Governor Limits.

59. Will the Triggers be fired if there is an workflow/process builder that performs an action?

Before update and After update triggers will be refired when a field update occurs from processbuilder/workflow.





Related post