How many types of triggers in Salesforce?

DWQA QuestionsCategory: QuestionsHow many types of triggers in Salesforce?
Editor Staff asked 1 month ago

How many types of triggers in Salesforce?

1 Answers
Editor Staff answered 1 month ago

Below are the two types of Apex triggers in Salesforce:
Before triggers: It can be used to update or validate record values before it is saved to the database.

trigger TriggerName on ObjectName(before event) //Here event can be insert, update or delete
{
    code_block
}

After triggers: It can be used to access field values of the records that are set by the system (such as record’s ID or LastModifiedDate field) that are stored in the database and use this field value to do the changes in other records. Records that fire after the triggers are read-only.

trigger TriggerName on ObjectName(after event) //Here event can be insert, update or delete
{
    code_block
}