Our Support: During the COVID-19 outbreak, we request learners to CALL US for Special Discounts!

- Salesforce Blogs -

Execution Rules of Salesforce Triggers

Introduction

Salesforce is a popular and most used CRM by the organizations. In Salesforce, there are a number of processes that execute the main processor. The set of processes required and followed by the Salesforce are predefined and there is a proper list of rules that every Salesforce Developer must know. You can go through such questions in the Salesforce Advanced Developer Certification Exam, which is also known as DEV-501. In this exam, you can find a couple of questions on the rules, Salesforce trigger, and the concept of order of execution in Salesforce.

Salesforce administrators and developers must also know and understand these rules and the Salesforce trigger which gets fired when the condition gets satisfied. Salesforce evaluates the rules in its predefined set of lists. This blog for Salesforce order of execution covers all rules which are used by the Salesforce trigger and the process execution

Introduction to Salesforce Apex Triggers

Salesforce Apex can be invoked by triggers, which enables you to perform or take any of the custom or pre-defined actions when any changes occur in the Salesforce records. These operations can be insertion, deletion or updating of any record. Therefore the Apex triggers can be of the following types:

  • Before Triggers: They are used to validate any record before they  are saved in the database
  • After Trigger: It is used to access field values of records, which is set by the system

Any trigger executes before and after an update operation. The two types of triggers are fired as per their names and the value of the field gets updated accordingly. You can also see and check the list of rules on the Salesforce website as well. Following listed operations are covered by the triggers:

Introduction to Salesforce Apex Triggers

Among above-listed operation following operations are specified: Upsert triggers are fired both before and after the insert operation or before and after the update operation Merge triggers are fired both before and after the delete operation and before and after the update operation

Learn Salesforce in the Easiest Way

Read: Salesforce Lightning Interview Questions and Answers
  • Learn from the videos
  • Learn anytime anywhere
  • Pocket-friendly mode of learning
  • Complimentary eBook available

Triggers and Salesforce Order of Execution Rules

There can be the following cases for Trigger execution for which the rules are specified in Salesforce. These rules are standard.

  • System Validation Rule
  • Before Triggers are executed
  • After Trigger Execution
  • Custom Validation Rule
  • Assignment Rules
  • Auto-Response Rules
  • Workflow Rules
  • Escalation Rules
  • Before Trigger Rules
  • After Trigger Rules
  • Criteria Based Sharing Rules
  • Post-Commit Rule

When any record is saved in the Salesforce then the following events occur in order on the server side:

  • The original record loaded from the database of the statement of up sert or insert or update
  • The field value of the record is loaded and the new value is overwritten on the old value. In case if the record is updated through Standard UI edit page then the Salesforce applies validation rules to check the records for following:

1). Validates the record for maximum field length

2). Validates for field formats

3). Checks the value for layout and field level value

4). Check for layout specific rules

Read: Top 20 Salesforce Alternatives: Is There Good CRM Competitor to Salesforce?

Salesforce validates only the foreign key if the request comes from another source like Apex application or SOAP API. salesforce quiz

  • All rules defined in before triggers
  • Most system validation steps are executed like to verify the null values of fields and to ensure the user-defined validation rules. Salesforce does not run secondly defined system validation rules
  • The rule of duplicate is applied
  • The record is saved in the database
  • Now all after triggers get executed
  • All assignment rulesget executed
  • Auto-response rules get executed
  • Workflow rules get executed
  • If any record or field rule is there in workflow then it gets updated
  • If the record is updated through workflow trigger, then once againbefore trigger and after trigger is fired and standard validation, custom validation, duplicate and escalation rules are also executed once again
  • Now all escalation rules get executed
  • Then all entitlement rules get executed
  • If the roll-up summary is there then it gets executed
  • Criteria based sharing gets evaluated
  • All DML operations are committed
  • Post-commit logic gets executed, e.g. sending emails

Salesforce Training For Administrators & Developers

  • No cost for a Demo Class
  • Industry Expert as your Trainer
  • Available as per your schedule
  • Customer Support Available

The above-listed rules are followed by the triggers and there are a few additional constraints as well, which should be considered while applying the triggers. These additional considerations are in  some specific cases for the triggers which are used in the record:

  • Above listed order of execution of rules cannot be guaranteed if there are multiple triggers for the same object and event. Here you can take the example of the case when two triggers are specified for before case and at the time of new record insertion, the order of these trigger firing cannot be guaranteed.
  • If there is any before trigger which is used to set the stage and forecast categories for any opportunity record. The trigger will behave as follows:

1). If you will set the forecast and stage category for the record, then check that opportunity record should contain exact values

2). If the stage is set for any record, but the Forecast Category value is not set for any opportunity record then a default trigger value is set

3). If a value specified in API call or the value is coming from the user interface as Forecast Category value must also come from the same source. In case if the Forecast category is not specified,then the default value is taken from the trigger.

Read: What are Field Dependencies? How to create Field Dependency in Salesforce?

Salesforce Order of Execution and Salesforce Trigger Example

If you are aware of the above-listed rules then it will become easy to configure and troubleshoot the apps. Here you can take the example when the Lead assignment rule is already defined and specified in the Salesforce through which all the leads are assigned by default to “Ben Stuart” and there is another workflow action which sets the owner to “Mellisa Lee”, then in such case when a new lead will be generated, then Salesforce will run first rule or trigger and then it will run the specified workflow rule, so the final value of the lead will be set to “Mellisa Lee”. In case if your system does not behave in an expected manner, then you can run a debug log through which you can check the step which may provide you detailed information about the value.

Salesforce Training For Administrators & Developers

  • Personalized Free Consultation
  • Access to Our Learning Management System
  • Access to Our Course Curriculum
  • Be a Part of Our Free Demo Class

Final Words

Salesforce Triggers are important if you have to maintain a large database. These triggers are of various types and are applied at the time of storing and retrieval of any data value from the database. The triggers are the most important feature of the Salesforce database and the rules which are set by Salesforce for trigger execution can provide you a detailed view of their execution. The triggers and their associated rule knowledge cannot only make your task of app execution simpler but knowledge of their execution can make the complete process quick. Even a Salesforce developer can easily specify and customize these rules while defining the application.



Salesforce Tutorial Overview


    Janbask Training

    A dynamic, highly professional, and a global online training course provider committed to propelling the next generation of technology learners with a whole new way of training experience.


Comments

Trending Courses

AWS

  • AWS & Fundamentals of Linux
  • Amazon Simple Storage Service
  • Elastic Compute Cloud
  • Databases Overview & Amazon Route 53

Upcoming Class

3 days 14 Jul 2020

DevOps

  • Intro to DevOps
  • GIT and Maven
  • Jenkins & Ansible
  • Docker and Cloud Computing

Upcoming Class

-1 day 10 Jul 2020

Data Science

  • Data Science Introduction
  • Hadoop and Spark Overview
  • Python & Intro to R Programming
  • Machine Learning

Upcoming Class

5 days 16 Jul 2020

Hadoop

  • Architecture, HDFS & MapReduce
  • Unix Shell & Apache Pig Installation
  • HIVE Installation & User-Defined Functions
  • SQOOP & Hbase Installation

Upcoming Class

6 days 17 Jul 2020

Salesforce

  • Salesforce Configuration Introduction
  • Security & Automation Process
  • Sales & Service Cloud
  • Apex Programming, SOQL & SOSL

Upcoming Class

4 days 15 Jul 2020

QA

  • Introduction and Software Testing
  • Software Test Life Cycle
  • Automation Testing and API Testing
  • Selenium framework development using Testing

Upcoming Class

-1 day 10 Jul 2020

Business Analyst

  • BA & Stakeholders Overview
  • BPMN, Requirement Elicitation
  • BA Tools & Design Documents
  • Enterprise Analysis, Agile & Scrum

Upcoming Class

3 days 14 Jul 2020

MS SQL Server

  • Introduction & Database Query
  • Programming, Indexes & System Functions
  • SSIS Package Development Procedures
  • SSRS Report Design

Upcoming Class

4 days 15 Jul 2020

Python

  • Features of Python
  • Python Editors and IDEs
  • Data types and Variables
  • Python File Operation

Upcoming Class

12 days 23 Jul 2020

Artificial Intelligence

  • Components of AI
  • Categories of Machine Learning
  • Recurrent Neural Networks
  • Recurrent Neural Networks

Upcoming Class

3 days 14 Jul 2020

Machine Learning

  • Introduction to Machine Learning & Python
  • Machine Learning: Supervised Learning
  • Machine Learning: Unsupervised Learning

Upcoming Class

6 days 17 Jul 2020

Tableau

  • Introduction to Tableau Desktop
  • Data Transformation Methods
  • Configuring tableau server
  • Integration with R & Hadoop

Upcoming Class

2 days 13 Jul 2020

Search Posts

Reset

Receive Latest Materials and Offers on Salesforce Course

Interviews