Today's Offer - Salesforce Certification Training - Enroll at Flat 10% Off.

- Salesforce Blogs -

Execution Rules of Salesforce Triggers

Salesforce is a popular and most used CRM by the organizations. In Salesforce, there are a number of processes which execute the main processor. The set of processes which are required and followed by the Salesforce are pre-defined and there is a proper list of rules which 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 and concept of order of execution.

Salesforce administrator and developers must also know and understand these rules and the triggers which get fired when the condition gets satisfied. Salesforce evaluates the rules in its pre-defined set of list. This blog covers all rules which are used by Salesforce triggers and process execution salesforce Curriculum

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 action 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  aresaved in the database

After Trigger: It is used to access field values of records, which is set by the system

Read: An Introduction to Apex Class in Salesforce for Beginners

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

Triggers and Order of Execution Rules         

There can be 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

Read: What Are The Validation Rules? How To Create Salesforce Validation Rules?

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

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 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

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

Read: All you want to know about Junction Object - Salesforce

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.

An 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. free salesforce demo 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 Salesforce database and the rules which are set by Salesforce for trigger execution can provide you the 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.

Read: What Are The Differences Between Sugarcrm & Salesforce?

Salesforce Tutorial Overview


    Janbask Training

    JanBask Training is a leading Global Online Training Provider through Live Sessions. The Live classes provide a blended approach of hands on experience along with theoretical knowledge which is driven by certified professionals.


Trending Courses

AWS

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

Upcoming Class

8 days 14 Dec 2019

DevOps

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

Upcoming Class

9 days 15 Dec 2019

Data Science

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

Upcoming Class

9 days 15 Dec 2019

Hadoop

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

Upcoming Class

-0 day 06 Dec 2019

Salesforce

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

Upcoming Class

14 days 20 Dec 2019

Course for testing

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

Upcoming Class

18 days 24 Dec 2019

QA

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

Upcoming Class

3 days 09 Dec 2019

Business Analyst

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

Upcoming Class

-0 day 06 Dec 2019

SQL Server

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

Upcoming Class

3 days 09 Dec 2019

Comments

Search Posts

Reset

Receive Latest Materials and Offers on Salesforce Course

Interviews