Grab Deal : Flat 30% off on live classes + 2 free self-paced courses! - SCHEDULE CALL

- 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 Business Analyst Career Path - A Comprehensive Guide
  • 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

Read: How to Create Assignment Rules in Salesforce? [Updated in 2020]

4). Check for layout specific rules

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

Read: How to Use Salesforce CRM Effectively for Project Management?

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.

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

fbicons FaceBook twitterTwitter google+Google+ lingedinLinkedIn pinterest Pinterest emailEmail

     Logo

    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.


  • fb-15
  • twitter-15
  • linkedin-15

Comments

Trending Courses

Cyber Security Course

Cyber Security

  • Introduction to cybersecurity
  • Cryptography and Secure Communication 
  • Cloud Computing Architectural Framework
  • Security Architectures and Models
Cyber Security Course

Upcoming Class

1 day 27 Apr 2024

QA Course

QA

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

Upcoming Class

0 day 26 Apr 2024

Salesforce Course

Salesforce

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

Upcoming Class

0 day 26 Apr 2024

Business Analyst Course

Business Analyst

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

Upcoming Class

21 days 17 May 2024

MS SQL Server Course

MS SQL Server

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

Upcoming Class

0 day 26 Apr 2024

Data Science Course

Data Science

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

Upcoming Class

0 day 26 Apr 2024

DevOps Course

DevOps

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

Upcoming Class

-1 day 25 Apr 2024

Hadoop Course

Hadoop

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

Upcoming Class

0 day 26 Apr 2024

Python Course

Python

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

Upcoming Class

8 days 04 May 2024

Artificial Intelligence Course

Artificial Intelligence

  • Components of AI
  • Categories of Machine Learning
  • Recurrent Neural Networks
  • Recurrent Neural Networks
Artificial Intelligence Course

Upcoming Class

1 day 27 Apr 2024

Machine Learning Course

Machine Learning

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

Upcoming Class

35 days 31 May 2024

 Tableau Course

Tableau

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

Upcoming Class

0 day 26 Apr 2024

Search Posts

Reset

Receive Latest Materials and Offers on Salesforce Course

Interviews