Page 1

Essentials to Become an Expert in Salesforce Apex Triggers

Copyright Š JanBask Training. All rights reserved

www.JanBaskTraining.com


Introduction

Triggers are scripts in Apex that get executed either before or post the happening of specific DML (data manipulation language) events.

Copyright Š JanBask Training. All rights reserved

www.JanBaskTraining.com


objective

✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓

Copyright © JanBask Training. All rights reserved

Introduction Key Points of Triggers Trigger Syntax Code Events in Trigger Syntax Types of Triggers Key Consideration Trigger Exceptions Bulk Triggers Context Variables Conclusion

www.JanBaskTraining.com


Key Points of Triggers

• Many actions like insertions, deletions, etc. can be performed to the Salesforce records • There in the database system support triggers • Triggers are employed in performing those operations that are backed by certain conditions like for modification of some linked records or even preventing some operations from taking place. • Triggers are thus used for almost anything in Apex which also includes execution of SOQL and DML. • Triggers can also be employed for the performance of those tasks which cannot be undertaken by making use of the point-and-click tools in the Salesforce user interface.

Copyright © JanBask Training. All rights reserved

www.JanBaskTraining.com


Trigger Syntax Code

Copyright © JanBask Training. All rights reserved

www.JanBaskTraining.com


Events in Trigger Syntax

• Before insert • Before update

• Before delete • After insert • After update • After delete • After undelete

Copyright © JanBask Training. All rights reserved

www.JanBaskTraining.com


Types of Triggers

Before Triggers: They are basically used for both the validation and update of various values before they have been saved in the database.

Copyright Š JanBask Training. All rights reserved

After Triggers: They are used for accessing the field values which are earmarked by the system. It is also useful in affecting changes in other records. Every record which actually fires the after the trigger is a read-only record.

www.JanBaskTraining.com


Key Consideration

• Upsert triggers are used for firing triggers both prior to the insert and even post the insert. It can also fire before or after the update triggers, whichever scenario fits better. • Merge triggers, likewise are used for firing both before and after the delete for the records which are losing. It can also fire for both prior to and post the update triggers for the records which are winning. • It has been seen that the triggers that are executed post records are not deleted only end up working with certain particular objects. • There is no recording of the field history till the trigger ends. • The tracking of field history is subject to the permissions of the user, and if the latter does not have the suitable permissions but ends up in activating the trigger which makes some change to the object or field which has tracking enabled for history, no changes will be made in the history. • All kinds of callouts have to be made asynchronously from a trigger so as not to block the trigger process until there is no response for the external service.

Copyright © JanBask Training. All rights reserved

www.JanBaskTraining.com


Trigger Exceptions

• Triggers are also used for the prevention of DML operations from taking place by calling on the addError() method either on a record or a field. • New Records in both the insert and update triggers, and also on Trigger. • Old Records in delete triggers, the custom error message shows up on the interface of the application, and it is also logged.

Copyright © JanBask Training. All rights reserved

www.JanBaskTraining.com


Bulk Triggers Bulk triggers are helpful in the handling of both solo record updates and other kinds of bulk operations, for instance:

• • • •

Import of Data Bulk API calls on the Lightning platform Bulk or mass actions Other kinds of recursive methods in Apex can call DML statements in bulk

Copyright © JanBask Training. All rights reserved

www.JanBaskTraining.com


Context Variables • isExecuting • isInsert • isUpdate • isDelete / isUndelete • isBefore / isAfter • new / old • newMap / oldMap • operationType

• size

Copyright © JanBask Training. All rights reserved

www.JanBaskTraining.com


Conclusion

• Knowledge of the basic aspects of the Apex triggers by taking some suitable training and certifications • So you are able to address the core issues in the same • JanBask Training has state of the art training modules which address all these core points along with many other vital aspects of Salesforce to prepare you for the future.

Copyright © JanBask Training. All rights reserved

www.JanBaskTraining.com


Thank You Happy Learning

Copyright © JanBask Training. All rights reserved

www.JanBaskTraining.com

Profile for JanBaskTraining

Become an Expert in Salesforce Apex Triggers | JanBask Training  

Trigger support provided by Apex for management of records, as is there in the database system support triggers. Get Certification in Salesf...

Become an Expert in Salesforce Apex Triggers | JanBask Training  

Trigger support provided by Apex for management of records, as is there in the database system support triggers. Get Certification in Salesf...