The function of good software is to make the complex appear to be simple.
Salesforce Platform (formerly known as Force.com) is a Platform As a Service(PaaS) that allows developers to create add-on applications that integrate into the main Salesforce.com application.
One of the reasons that Salesforce is so popular is that it is packed with features like no other CRM software.
What are Triggers in Salesforce?
A trigger is an Apex script that executes before or after data manipulation language (DML) events occur. Apex triggers enable you to perform custom actions before or after events to record in Salesforce. Such as insertions, updates, or deletions. Just like database systems support triggers, Apex provides trigger support for managing records.
When to use salesforce triggers
We should use triggers to perform tasks that can’t be done by using the point-and-click tools in the Salesforce user interface. For example, if validating a field value or updating a field on a record, use validation rules and workflow rules instead.
Types of triggers in Salesforce
There are two types of triggers:
- Before triggers are used to perform a task before a record is inserted or updated or deleted. These are used to update or validate record values before they are saved to the database.
- After triggers are used, when we want to use the information set by the Salesforce system and make changes in the other records. This trigger is used to access field values that are set by the system.(such as a record’s Id or LastModifiedDate field), and to affect changes in other records. The records that fire the after the trigger are read-only.
What are the considerations while implementing the Triggers?
Consider the following before implementing the triggers.
- Upsert trigger fires on 4 different events :- before(insert, update), after (insert, update)
- Merge triggers are fired on both events on delete
- Field history is updated after the trigger has successfully finished processing data.
- Any callout should be asynchronous so that trigger does not have to wait for the response.
- A trigger cannot have a static keyword in its code.
- If a trigger completes successfully the changes are committed to the database. And if it fails the transaction is rolled back.
Where to find triggers in Salesforce?
To view the details for a trigger, from Setup, enter Apex Triggers in the Quick Find box, then select Apex Triggers, then click the name of the trigger. You can also access the trigger details from the object management settings for an object.
When trigger will fire in Salesforce?
Triggers can fire twice, once before workflows and once after workflow. The before and after triggers fire one more time only when something needs to be updated. If the fields have already been set to a value, the triggers are not fired again.
At TCI we also have a fully-fledged team of Salesforce developers and architects. If you also want to learn more about Salesforce or want to work on some exciting projects, you can contact us.