SlideShare a Scribd company logo
Triggers and order of execution1
Topics to be covered:
1. What are triggers?
2. Operations where trigger execute.
3. Implementation Considerations
4. Types of trigger.
5. Trigger syntax and usage .
6. Trigger context variables
7. Order of execution
8. Queries
Triggers
Definition:
Apex can be invoked through the use of triggers.
A trigger is Apex code that executes before or after the following types of
operations:
Insert
Update
Delete
Merge
Upsert
undelete
Triggers
Implementation Considerations:
upsert triggers fire both before and after insert or before and after update triggers as
appropriate.
merge triggers fire both before and after delete triggers for the losing records and
before update triggers for the winning record only.
Triggers that execute after a record has been undeleted only work with specific objects
Field history is not recorded until the end of a trigger. If you query field history in a
trigger, you will not see any history for the current transaction.
Types of Triggers:
Before triggers are used to update or validate record values before they are
saved to the database. A before insert trigger can change the value in the field.
We won't get before undelete trigger.
After triggers can be used for a much more complex purposes, like updating a
value of some other object when this is updated. Or it can also be used to
trigger some other event (like workflow and approval process).
Triggers
Syntax:
trigger triggerName on ObjectName (trigger_events) { code_block }
Uses for triggers:
Enforce business rules
Validate input data
Write to other files for audit trail purposes
Query from other files for cross-referencing purposes
Access system functions (for example, print an exception message when a rule is violat
Replicate data to different files to achieve data consistency
Trigger Context Variables
Triggers define implicit variables that allow developers to access
runtime context.
•isExecuting
•isInsert
•isUpdate
•isDelete
•isBefore
•isAfter
•isUndelete
•New
•newMap
•Old
•oldMap
•size
Order of Execution
When user save a record with an insert, update, or upsert statement,
Salesforce performs the following events in order.
1. Loads the original record from the database or initializes the record for an upsert
statement.
2. Loads the new record field values from the request and overwrites the old values.
If the request came from a standard UI edit page, Salesforce runs system validation
to check the record for:
a. Compliance with layout-specific rules
b. Required values at the layout level and field-definition level
c. Valid field formats
d. Maximum field length
Order of Execution
3. Executes all before triggers.
4. Runs most system validation steps again, such as verifying that all required fields
have a non-null value, and runs any user-defined validation rules. But no
validation rule of layout-specific is run again.
5. Saves the record to the database, but doesn't commit yet.
6. Executes all after triggers.
7. Executes assignment rules.
8. Executes auto-response rules.
9. Executes workflow rules.
10. If there are workflow field updates, updates the record again.
11. If the record was updated with workflow field updates, fires before and after
triggers one more time, in addition to standard validations. Custom validation
rules are not run again.
12. Executes escalation rules.
13. If the record contains a roll-up summary field or is part of a cross-object workflow,
performs calculations and updates the roll-up summary field in the parent record.
Parent record goes through save procedure.
Order of Execution
14. If the parent record is updated, and a grand-parent record contains a roll-up summa
field or is part of a cross-object workflow, performs calculations and updates the
roll-up summary field in the parent record. Grand-parent record goes through save
procedure.
15. Executes Criteria Based Sharing evaluation.
16. Commits all DML operations to the database.
17. Executes post-commit logic, such as sending email.
Reference links
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers.htm
http://help.salesforce.com/HTViewHelpDoc?id=code_define_trigger.htm
http://www.salesforce.com/us/developer/docs/apexcode/Content/
apex_triggers_context_variables_considerations.htm
http://www.salesforce.com/us/developer/docs/apexcode/Content/
apex_triggers_context_variables.htm
http://www.salesforce.com/us/developer/docs/apexcode/Content/
apex_triggers_order_of_execution.htm
Triggers and order of execution1
Triggers and Order of Execution
Ad

More Related Content

What's hot (20)

All About Test Class in #Salesforce
All About Test Class in #SalesforceAll About Test Class in #Salesforce
All About Test Class in #Salesforce
Amit Singh
 
Asynchronous apex
Asynchronous apexAsynchronous apex
Asynchronous apex
furuCRM株式会社 CEO/Dreamforce Vietnam Founder
 
Best Practices for RESTful Web Services
Best Practices for RESTful Web ServicesBest Practices for RESTful Web Services
Best Practices for RESTful Web Services
Salesforce Developers
 
Oracle Purchasing – Different types of Receiving Options
Oracle Purchasing – Different types of Receiving OptionsOracle Purchasing – Different types of Receiving Options
Oracle Purchasing – Different types of Receiving Options
Boopathy CS
 
Data Management and Migration in Salesforce
Data Management and Migration in SalesforceData Management and Migration in Salesforce
Data Management and Migration in Salesforce
Sunil kumar
 
Introduction to apex code
Introduction to apex codeIntroduction to apex code
Introduction to apex code
EdwinOstos
 
Salesforce Development Best Practices
Salesforce Development Best PracticesSalesforce Development Best Practices
Salesforce Development Best Practices
Vivek Chawla
 
Inventory receiving processes for serial controlled items
Inventory receiving processes for serial controlled itemsInventory receiving processes for serial controlled items
Inventory receiving processes for serial controlled items
Avishek Roychoudhuri
 
Salesforce integration best practices columbus meetup
Salesforce integration best practices   columbus meetupSalesforce integration best practices   columbus meetup
Salesforce integration best practices columbus meetup
MuleSoft Meetup
 
Lwc presentation
Lwc presentationLwc presentation
Lwc presentation
Nithesh N
 
Introduction to lightning Web Component
Introduction to lightning Web ComponentIntroduction to lightning Web Component
Introduction to lightning Web Component
Mohith Shrivastava
 
Kanban in Oracle Applications
Kanban in Oracle ApplicationsKanban in Oracle Applications
Kanban in Oracle Applications
mgarg82
 
Introduction to Lightning Web Component
Introduction to Lightning Web Component Introduction to Lightning Web Component
Introduction to Lightning Web Component
SmritiSharan1
 
Governor limits
Governor limitsGovernor limits
Governor limits
Shivanath Devinarayanan
 
Primeros pasos con ReactNative
Primeros pasos con ReactNativePrimeros pasos con ReactNative
Primeros pasos con ReactNative
Irene Alonso Candelario
 
Springboot Microservices
Springboot MicroservicesSpringboot Microservices
Springboot Microservices
NexThoughts Technologies
 
Lightning web components - Episode 1 - An Introduction
Lightning web components - Episode 1 - An IntroductionLightning web components - Episode 1 - An Introduction
Lightning web components - Episode 1 - An Introduction
Salesforce Developers
 
Record sharing model in salesforce
Record sharing model in salesforceRecord sharing model in salesforce
Record sharing model in salesforce
Sunil kumar
 
Deep Dive into Apex Triggers
Deep Dive into Apex TriggersDeep Dive into Apex Triggers
Deep Dive into Apex Triggers
Salesforce Developers
 
Decluttering your Salesfroce org
Decluttering your Salesfroce orgDecluttering your Salesfroce org
Decluttering your Salesfroce org
Roy Gilad
 
All About Test Class in #Salesforce
All About Test Class in #SalesforceAll About Test Class in #Salesforce
All About Test Class in #Salesforce
Amit Singh
 
Best Practices for RESTful Web Services
Best Practices for RESTful Web ServicesBest Practices for RESTful Web Services
Best Practices for RESTful Web Services
Salesforce Developers
 
Oracle Purchasing – Different types of Receiving Options
Oracle Purchasing – Different types of Receiving OptionsOracle Purchasing – Different types of Receiving Options
Oracle Purchasing – Different types of Receiving Options
Boopathy CS
 
Data Management and Migration in Salesforce
Data Management and Migration in SalesforceData Management and Migration in Salesforce
Data Management and Migration in Salesforce
Sunil kumar
 
Introduction to apex code
Introduction to apex codeIntroduction to apex code
Introduction to apex code
EdwinOstos
 
Salesforce Development Best Practices
Salesforce Development Best PracticesSalesforce Development Best Practices
Salesforce Development Best Practices
Vivek Chawla
 
Inventory receiving processes for serial controlled items
Inventory receiving processes for serial controlled itemsInventory receiving processes for serial controlled items
Inventory receiving processes for serial controlled items
Avishek Roychoudhuri
 
Salesforce integration best practices columbus meetup
Salesforce integration best practices   columbus meetupSalesforce integration best practices   columbus meetup
Salesforce integration best practices columbus meetup
MuleSoft Meetup
 
Lwc presentation
Lwc presentationLwc presentation
Lwc presentation
Nithesh N
 
Introduction to lightning Web Component
Introduction to lightning Web ComponentIntroduction to lightning Web Component
Introduction to lightning Web Component
Mohith Shrivastava
 
Kanban in Oracle Applications
Kanban in Oracle ApplicationsKanban in Oracle Applications
Kanban in Oracle Applications
mgarg82
 
Introduction to Lightning Web Component
Introduction to Lightning Web Component Introduction to Lightning Web Component
Introduction to Lightning Web Component
SmritiSharan1
 
Lightning web components - Episode 1 - An Introduction
Lightning web components - Episode 1 - An IntroductionLightning web components - Episode 1 - An Introduction
Lightning web components - Episode 1 - An Introduction
Salesforce Developers
 
Record sharing model in salesforce
Record sharing model in salesforceRecord sharing model in salesforce
Record sharing model in salesforce
Sunil kumar
 
Decluttering your Salesfroce org
Decluttering your Salesfroce orgDecluttering your Salesfroce org
Decluttering your Salesfroce org
Roy Gilad
 

Viewers also liked (20)

Introduction to Apex Triggers
Introduction to Apex TriggersIntroduction to Apex Triggers
Introduction to Apex Triggers
Salesforce Developers
 
Apex Trigger Debugging: Solving the Hard Problems
Apex Trigger Debugging: Solving the Hard ProblemsApex Trigger Debugging: Solving the Hard Problems
Apex Trigger Debugging: Solving the Hard Problems
Salesforce Developers
 
Salesforce Presentation
Salesforce PresentationSalesforce Presentation
Salesforce Presentation
Chetna Purohit
 
Configuration tips
Configuration tipsConfiguration tips
Configuration tips
vraopolisetti
 
Updating your user profile in communities
Updating your user profile in communitiesUpdating your user profile in communities
Updating your user profile in communities
DC Nonprofit Salesforce User Group
 
Introduction to Apex Triggers
Introduction to Apex TriggersIntroduction to Apex Triggers
Introduction to Apex Triggers
Salesforce Developers
 
Apex triggers, force_ide_and_deployment
Apex triggers, force_ide_and_deploymentApex triggers, force_ide_and_deployment
Apex triggers, force_ide_and_deployment
subhajit0209
 
Developing Salesforce Console Apps with Visualforce & the Integration Toolkit
Developing Salesforce Console Apps with Visualforce & the Integration ToolkitDeveloping Salesforce Console Apps with Visualforce & the Integration Toolkit
Developing Salesforce Console Apps with Visualforce & the Integration Toolkit
Andrew Mahood
 
Brisbane Salesforce User Group - May 2015 - Lightning Process Builder
Brisbane Salesforce User Group - May 2015 - Lightning Process BuilderBrisbane Salesforce User Group - May 2015 - Lightning Process Builder
Brisbane Salesforce User Group - May 2015 - Lightning Process Builder
Kevin Akermanis
 
Customizing the Salesforce Console With the Integration Toolkit
Customizing the Salesforce Console With the Integration ToolkitCustomizing the Salesforce Console With the Integration Toolkit
Customizing the Salesforce Console With the Integration Toolkit
Salesforce Developers
 
Salesforce API: Salesforce Console Deep Dive
Salesforce API: Salesforce Console Deep DiveSalesforce API: Salesforce Console Deep Dive
Salesforce API: Salesforce Console Deep Dive
Salesforce Developers
 
Approval process
Approval processApproval process
Approval process
mallareddy0107
 
Introduction to Apex Triggers
Introduction to Apex TriggersIntroduction to Apex Triggers
Introduction to Apex Triggers
Salesforce Developers
 
Getting started with Salesforce security
Getting started with Salesforce securityGetting started with Salesforce security
Getting started with Salesforce security
Salesforce Admins
 
Introduction to Salesforce validation rules new
Introduction to Salesforce validation rules newIntroduction to Salesforce validation rules new
Introduction to Salesforce validation rules new
Omprakash Saini
 
Exposing Salesforce REST Services Using Swagger
Exposing Salesforce REST Services Using SwaggerExposing Salesforce REST Services Using Swagger
Exposing Salesforce REST Services Using Swagger
Salesforce Developers
 
Salesforce Application Lifecycle Management presented to EA Forum by Sam Garf...
Salesforce Application Lifecycle Management presented to EA Forum by Sam Garf...Salesforce Application Lifecycle Management presented to EA Forum by Sam Garf...
Salesforce Application Lifecycle Management presented to EA Forum by Sam Garf...
Sam Garforth
 
Workflow in Salesforce
Workflow in SalesforceWorkflow in Salesforce
Workflow in Salesforce
MST Solutions LLC
 
Salesforce.com API Series: Service Cloud Console Deep Dive
Salesforce.com API Series: Service Cloud Console Deep DiveSalesforce.com API Series: Service Cloud Console Deep Dive
Salesforce.com API Series: Service Cloud Console Deep Dive
Salesforce Developers
 
Best Practices for Team Development in a Single Org
Best Practices for Team Development in a Single OrgBest Practices for Team Development in a Single Org
Best Practices for Team Development in a Single Org
Salesforce Developers
 
Apex Trigger Debugging: Solving the Hard Problems
Apex Trigger Debugging: Solving the Hard ProblemsApex Trigger Debugging: Solving the Hard Problems
Apex Trigger Debugging: Solving the Hard Problems
Salesforce Developers
 
Salesforce Presentation
Salesforce PresentationSalesforce Presentation
Salesforce Presentation
Chetna Purohit
 
Configuration tips
Configuration tipsConfiguration tips
Configuration tips
vraopolisetti
 
Apex triggers, force_ide_and_deployment
Apex triggers, force_ide_and_deploymentApex triggers, force_ide_and_deployment
Apex triggers, force_ide_and_deployment
subhajit0209
 
Developing Salesforce Console Apps with Visualforce & the Integration Toolkit
Developing Salesforce Console Apps with Visualforce & the Integration ToolkitDeveloping Salesforce Console Apps with Visualforce & the Integration Toolkit
Developing Salesforce Console Apps with Visualforce & the Integration Toolkit
Andrew Mahood
 
Brisbane Salesforce User Group - May 2015 - Lightning Process Builder
Brisbane Salesforce User Group - May 2015 - Lightning Process BuilderBrisbane Salesforce User Group - May 2015 - Lightning Process Builder
Brisbane Salesforce User Group - May 2015 - Lightning Process Builder
Kevin Akermanis
 
Customizing the Salesforce Console With the Integration Toolkit
Customizing the Salesforce Console With the Integration ToolkitCustomizing the Salesforce Console With the Integration Toolkit
Customizing the Salesforce Console With the Integration Toolkit
Salesforce Developers
 
Salesforce API: Salesforce Console Deep Dive
Salesforce API: Salesforce Console Deep DiveSalesforce API: Salesforce Console Deep Dive
Salesforce API: Salesforce Console Deep Dive
Salesforce Developers
 
Approval process
Approval processApproval process
Approval process
mallareddy0107
 
Getting started with Salesforce security
Getting started with Salesforce securityGetting started with Salesforce security
Getting started with Salesforce security
Salesforce Admins
 
Introduction to Salesforce validation rules new
Introduction to Salesforce validation rules newIntroduction to Salesforce validation rules new
Introduction to Salesforce validation rules new
Omprakash Saini
 
Exposing Salesforce REST Services Using Swagger
Exposing Salesforce REST Services Using SwaggerExposing Salesforce REST Services Using Swagger
Exposing Salesforce REST Services Using Swagger
Salesforce Developers
 
Salesforce Application Lifecycle Management presented to EA Forum by Sam Garf...
Salesforce Application Lifecycle Management presented to EA Forum by Sam Garf...Salesforce Application Lifecycle Management presented to EA Forum by Sam Garf...
Salesforce Application Lifecycle Management presented to EA Forum by Sam Garf...
Sam Garforth
 
Workflow in Salesforce
Workflow in SalesforceWorkflow in Salesforce
Workflow in Salesforce
MST Solutions LLC
 
Salesforce.com API Series: Service Cloud Console Deep Dive
Salesforce.com API Series: Service Cloud Console Deep DiveSalesforce.com API Series: Service Cloud Console Deep Dive
Salesforce.com API Series: Service Cloud Console Deep Dive
Salesforce Developers
 
Best Practices for Team Development in a Single Org
Best Practices for Team Development in a Single OrgBest Practices for Team Development in a Single Org
Best Practices for Team Development in a Single Org
Salesforce Developers
 
Ad

Similar to Triggers and order of execution1 (20)

Advanced Topics on Database - Unit-3 AU17
Advanced Topics on Database - Unit-3 AU17Advanced Topics on Database - Unit-3 AU17
Advanced Topics on Database - Unit-3 AU17
LOGANATHANK24
 
Salesforce testing best_practices
Salesforce testing best_practicesSalesforce testing best_practices
Salesforce testing best_practices
Vijayaragavan k 🌩️
 
Qtp manual testing tutorials by QuontraSolutions
Qtp manual testing tutorials by QuontraSolutionsQtp manual testing tutorials by QuontraSolutions
Qtp manual testing tutorials by QuontraSolutions
QUONTRASOLUTIONS
 
Active database
Active databaseActive database
Active database
Dabbal Singh Mahara
 
Become an Expert in Salesforce Apex Triggers | JanBask Training
 Become an Expert in Salesforce Apex Triggers | JanBask Training Become an Expert in Salesforce Apex Triggers | JanBask Training
Become an Expert in Salesforce Apex Triggers | JanBask Training
JanBask Training
 
Control Freak: Risk and Control in Azure DevOps
Control Freak: Risk and Control in Azure DevOpsControl Freak: Risk and Control in Azure DevOps
Control Freak: Risk and Control in Azure DevOps
AgileThought
 
Custom Controllers and Controller Extensions
Custom Controllers and Controller Extensions Custom Controllers and Controller Extensions
Custom Controllers and Controller Extensions
Mohammed Safwat Abu Kwaik
 
Change tracking
Change trackingChange tracking
Change tracking
Sonny56
 
LDV.pptx
LDV.pptxLDV.pptx
LDV.pptx
Shams Pirzada
 
Stored procedures
Stored proceduresStored procedures
Stored procedures
Muhammad Younis
 
Test Driven Development with Sql Server
Test Driven Development with Sql ServerTest Driven Development with Sql Server
Test Driven Development with Sql Server
David P. Moore
 
Large Data Volume Salesforce experiences
Large Data Volume Salesforce experiencesLarge Data Volume Salesforce experiences
Large Data Volume Salesforce experiences
Cidar Mendizabal
 
Docker, Zabbix and auto-scaling
Docker, Zabbix and auto-scalingDocker, Zabbix and auto-scaling
Docker, Zabbix and auto-scaling
Vitaly Peregudov
 
Data warehouse testing
Data warehouse testingData warehouse testing
Data warehouse testing
Er. Nawaraj Bhandari
 
Oracle data capture c dc
Oracle data capture c dcOracle data capture c dc
Oracle data capture c dc
Amit Sharma
 
Intro to tsql unit 14
Intro to tsql   unit 14Intro to tsql   unit 14
Intro to tsql unit 14
Syed Asrarali
 
Intro to tsql
Intro to tsqlIntro to tsql
Intro to tsql
Syed Asrarali
 
Qtp Training
Qtp TrainingQtp Training
Qtp Training
mehramit
 
Hybrid framework
Hybrid frameworkHybrid framework
Hybrid framework
Sudhakar Mangi
 
Marty, You're Just Not Thinking Fourth Dimensionally
Marty, You're Just Not Thinking Fourth DimensionallyMarty, You're Just Not Thinking Fourth Dimensionally
Marty, You're Just Not Thinking Fourth Dimensionally
Teamstudio
 
Advanced Topics on Database - Unit-3 AU17
Advanced Topics on Database - Unit-3 AU17Advanced Topics on Database - Unit-3 AU17
Advanced Topics on Database - Unit-3 AU17
LOGANATHANK24
 
Qtp manual testing tutorials by QuontraSolutions
Qtp manual testing tutorials by QuontraSolutionsQtp manual testing tutorials by QuontraSolutions
Qtp manual testing tutorials by QuontraSolutions
QUONTRASOLUTIONS
 
Become an Expert in Salesforce Apex Triggers | JanBask Training
 Become an Expert in Salesforce Apex Triggers | JanBask Training Become an Expert in Salesforce Apex Triggers | JanBask Training
Become an Expert in Salesforce Apex Triggers | JanBask Training
JanBask Training
 
Control Freak: Risk and Control in Azure DevOps
Control Freak: Risk and Control in Azure DevOpsControl Freak: Risk and Control in Azure DevOps
Control Freak: Risk and Control in Azure DevOps
AgileThought
 
Custom Controllers and Controller Extensions
Custom Controllers and Controller Extensions Custom Controllers and Controller Extensions
Custom Controllers and Controller Extensions
Mohammed Safwat Abu Kwaik
 
Change tracking
Change trackingChange tracking
Change tracking
Sonny56
 
Test Driven Development with Sql Server
Test Driven Development with Sql ServerTest Driven Development with Sql Server
Test Driven Development with Sql Server
David P. Moore
 
Large Data Volume Salesforce experiences
Large Data Volume Salesforce experiencesLarge Data Volume Salesforce experiences
Large Data Volume Salesforce experiences
Cidar Mendizabal
 
Docker, Zabbix and auto-scaling
Docker, Zabbix and auto-scalingDocker, Zabbix and auto-scaling
Docker, Zabbix and auto-scaling
Vitaly Peregudov
 
Oracle data capture c dc
Oracle data capture c dcOracle data capture c dc
Oracle data capture c dc
Amit Sharma
 
Intro to tsql unit 14
Intro to tsql   unit 14Intro to tsql   unit 14
Intro to tsql unit 14
Syed Asrarali
 
Qtp Training
Qtp TrainingQtp Training
Qtp Training
mehramit
 
Hybrid framework
Hybrid frameworkHybrid framework
Hybrid framework
Sudhakar Mangi
 
Marty, You're Just Not Thinking Fourth Dimensionally
Marty, You're Just Not Thinking Fourth DimensionallyMarty, You're Just Not Thinking Fourth Dimensionally
Marty, You're Just Not Thinking Fourth Dimensionally
Teamstudio
 
Ad

Recently uploaded (20)

Quality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdfQuality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdf
Dr. Bindiya Chauhan
 
Anti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptxAnti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptx
Mayuri Chavan
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-3-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 5-3-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 5-3-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-3-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx
contactwilliamm2546
 
SPRING FESTIVITIES - UK AND USA -
SPRING FESTIVITIES - UK AND USA            -SPRING FESTIVITIES - UK AND USA            -
SPRING FESTIVITIES - UK AND USA -
ColĂŠgio Santa Teresinha
 
Odoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo SlidesOdoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo Slides
Celine George
 
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACYUNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
DR.PRISCILLA MARY J
 
How to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POSHow to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POS
Celine George
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
How to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odooHow to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odoo
Celine George
 
LDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini UpdatesLDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini Updates
LDM Mia eStudios
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
How to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 WebsiteHow to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 Website
Celine George
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
Political History of Pala dynasty Pala Rulers NEP.pptx
Political History of Pala dynasty Pala Rulers NEP.pptxPolitical History of Pala dynasty Pala Rulers NEP.pptx
Political History of Pala dynasty Pala Rulers NEP.pptx
Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
Social Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy StudentsSocial Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy Students
DrNidhiAgarwal
 
Quality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdfQuality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdf
Dr. Bindiya Chauhan
 
Anti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptxAnti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptx
Mayuri Chavan
 
2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx
contactwilliamm2546
 
Odoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo SlidesOdoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo Slides
Celine George
 
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACYUNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
DR.PRISCILLA MARY J
 
How to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POSHow to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POS
Celine George
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
How to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odooHow to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odoo
Celine George
 
LDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini UpdatesLDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini Updates
LDM Mia eStudios
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
How to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 WebsiteHow to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 Website
Celine George
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
Social Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy StudentsSocial Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy Students
DrNidhiAgarwal
 

Triggers and order of execution1

  • 2. Topics to be covered: 1. What are triggers? 2. Operations where trigger execute. 3. Implementation Considerations 4. Types of trigger. 5. Trigger syntax and usage . 6. Trigger context variables 7. Order of execution 8. Queries
  • 3. Triggers Definition: Apex can be invoked through the use of triggers. A trigger is Apex code that executes before or after the following types of operations: Insert Update Delete Merge Upsert undelete
  • 4. Triggers Implementation Considerations: upsert triggers fire both before and after insert or before and after update triggers as appropriate. merge triggers fire both before and after delete triggers for the losing records and before update triggers for the winning record only. Triggers that execute after a record has been undeleted only work with specific objects Field history is not recorded until the end of a trigger. If you query field history in a trigger, you will not see any history for the current transaction.
  • 5. Types of Triggers: Before triggers are used to update or validate record values before they are saved to the database. A before insert trigger can change the value in the field. We won't get before undelete trigger. After triggers can be used for a much more complex purposes, like updating a value of some other object when this is updated. Or it can also be used to trigger some other event (like workflow and approval process).
  • 6. Triggers Syntax: trigger triggerName on ObjectName (trigger_events) { code_block } Uses for triggers: Enforce business rules Validate input data Write to other files for audit trail purposes Query from other files for cross-referencing purposes Access system functions (for example, print an exception message when a rule is violat Replicate data to different files to achieve data consistency
  • 7. Trigger Context Variables Triggers define implicit variables that allow developers to access runtime context. •isExecuting •isInsert •isUpdate •isDelete •isBefore •isAfter •isUndelete •New •newMap •Old •oldMap •size
  • 8. Order of Execution When user save a record with an insert, update, or upsert statement, Salesforce performs the following events in order. 1. Loads the original record from the database or initializes the record for an upsert statement. 2. Loads the new record field values from the request and overwrites the old values. If the request came from a standard UI edit page, Salesforce runs system validation to check the record for: a. Compliance with layout-specific rules b. Required values at the layout level and field-definition level c. Valid field formats d. Maximum field length
  • 9. Order of Execution 3. Executes all before triggers. 4. Runs most system validation steps again, such as verifying that all required fields have a non-null value, and runs any user-defined validation rules. But no validation rule of layout-specific is run again. 5. Saves the record to the database, but doesn't commit yet. 6. Executes all after triggers. 7. Executes assignment rules. 8. Executes auto-response rules. 9. Executes workflow rules. 10. If there are workflow field updates, updates the record again. 11. If the record was updated with workflow field updates, fires before and after triggers one more time, in addition to standard validations. Custom validation rules are not run again. 12. Executes escalation rules. 13. If the record contains a roll-up summary field or is part of a cross-object workflow, performs calculations and updates the roll-up summary field in the parent record. Parent record goes through save procedure.
  • 10. Order of Execution 14. If the parent record is updated, and a grand-parent record contains a roll-up summa field or is part of a cross-object workflow, performs calculations and updates the roll-up summary field in the parent record. Grand-parent record goes through save procedure. 15. Executes Criteria Based Sharing evaluation. 16. Commits all DML operations to the database. 17. Executes post-commit logic, such as sending email.
  • 13. Triggers and Order of Execution