A trigger is an Apex script that executes before or after certain events occur in DML, For example, before the object record is entered into the database or after the record has been deleted. Triggers allow you to carry out custom actions before or after changes to Salesforce records.
2. cloud.analogy info@cloudanalogy.com +1(415)830-3899
A trigger is an Apex script that executes before or after certain events occur in DML,
For example, before the object record is entered into the database or after the
record has been deleted. Triggers allow you to carry out custom actions before or
after changes to Salesforce records.
Two types of Apex triggers
Before trigger:
This trigger is used to update or verify the value of a record before it is saved in a
database.
What is a Trigger?
3. cloud.analogy info@cloudanalogy.com +1(415)830-3899
After trigger:
This trigger is used to access values of the record stored in a database and use this
value to make changes to other records.
Bulky Trigger:
By default, all triggers in Salesforce are bulky triggers. This means you can process
many records simultaneously.
What is a Trigger?
4. cloud.analogy info@cloudanalogy.com +1(415)830-3899
isExecuting - Returns true if the current context for the Apex code is a trigger, not a
Visualforce page, a Web service.
isInsert - Returns true if this trigger was fired due to an insert operation.
isUpdate - Returns true if this trigger was fired due to an update operation.
isDelete - Returns true if this trigger was fired due to a delete operation.
isBefore - Returns true if this trigger was fired before any record was saved.
isAfter - Returns true if this trigger was fired after all records were saved.
Trigger Context Variables
5. cloud.analogy info@cloudanalogy.com +1(415)830-3899
Trigger Context Variables
isUndelete - If a record is recovered from the recycle bin it returns trigger true.
new - Returns a list of the new versions of the sObject records
newMap - A map of IDs to the new versions of the sObject records
Old - Returns a list of the old versions of the sObject records.
oldMap - A map of IDs to the old versions of the sObject records.
Size - The total number of records in a trigger invocation.
6. cloud.analogy info@cloudanalogy.com +1(415)830-3899
Workflow
● It is an automated process that can shoot an action that is based on evaluation
and rule criteria.
● Performing DML operations in the workflow is not possible.
● We can obtain a workflow over an object.
● We can’t create a query from the database.
Triggers in Salesforce vs. Workflow
in Salesforce
7. Triggers in Salesforce vs. Workflow
in Salesforce
cloud.analogy info@cloudanalogy.com +1(415)830-3899
Trigger
● It is a piece of code that is executed either before or after a record is updated
or inserted.
● More than 15 DML operations can be used in a single trigger.
● More than 20 SOQLs can be used from the database in a trigger.
● We can access triggers across an object and related to that object.
8. Limitations of Workflows overcome by
Triggers in Salesforce
cloud.analogy info@cloudanalogy.com +1(415)830-3899
● Workflows are not able to create or update a separate object.
● You can’t reference certain fields when using workflows.
● You will not have your workflow doing more than just field updates and emails.