SlideShare a Scribd company logo
1 of 13
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 Execution

More Related Content

What's hot

Salesforce Development Best Practices
Salesforce Development Best PracticesSalesforce Development Best Practices
Salesforce Development Best PracticesVivek Chawla
 
SFDC Batch Apex
SFDC Batch ApexSFDC Batch Apex
SFDC Batch ApexSujit Kumar
 
ORM, JPA, & Hibernate Overview
ORM, JPA, & Hibernate OverviewORM, JPA, & Hibernate Overview
ORM, JPA, & Hibernate OverviewBrett Meyer
 
How to Analyze and Tune MySQL Queries for Better Performance
How to Analyze and Tune MySQL Queries for Better PerformanceHow to Analyze and Tune MySQL Queries for Better Performance
How to Analyze and Tune MySQL Queries for Better Performanceoysteing
 
Apex Enterprise Patterns: Building Strong Foundations
Apex Enterprise Patterns: Building Strong FoundationsApex Enterprise Patterns: Building Strong Foundations
Apex Enterprise Patterns: Building Strong FoundationsSalesforce Developers
 
Batchable vs @future vs Queueable
Batchable vs @future vs QueueableBatchable vs @future vs Queueable
Batchable vs @future vs QueueableBoris Bachovski
 
Oracle GoldenGate on Docker
Oracle GoldenGate on DockerOracle GoldenGate on Docker
Oracle GoldenGate on DockerBobby Curtis
 
[Pgday.Seoul 2021] 1. 예제로 살펴보는 포스트그레스큐엘의 독특한 SQL
[Pgday.Seoul 2021] 1. 예제로 살펴보는 포스트그레스큐엘의 독특한 SQL[Pgday.Seoul 2021] 1. 예제로 살펴보는 포스트그레스큐엘의 독특한 SQL
[Pgday.Seoul 2021] 1. 예제로 살펴보는 포스트그레스큐엘의 독특한 SQLPgDay.Seoul
 
Custom policies in mule 4 and a circuit breaker example
Custom policies in mule 4 and a circuit breaker exampleCustom policies in mule 4 and a circuit breaker example
Custom policies in mule 4 and a circuit breaker exampleRoyston Lobo
 
Oracle DB 19c: SQL Tuning Using SPM
Oracle DB 19c: SQL Tuning Using SPMOracle DB 19c: SQL Tuning Using SPM
Oracle DB 19c: SQL Tuning Using SPMArturo Aranda
 
Stumbling stones when migrating from Oracle
 Stumbling stones when migrating from Oracle Stumbling stones when migrating from Oracle
Stumbling stones when migrating from OracleEDB
 
Development Best Practices
Development Best PracticesDevelopment Best Practices
Development Best PracticesSalesforce Partners
 
Automate the operation of your Oracle Cloud infrastructure v2.0
Automate the operation of your Oracle Cloud infrastructure v2.0Automate the operation of your Oracle Cloud infrastructure v2.0
Automate the operation of your Oracle Cloud infrastructure v2.0Nelson Calero
 
Alfresco tuning part1
Alfresco tuning part1Alfresco tuning part1
Alfresco tuning part1Luis Cabaceira
 
대용량 분산 아키텍쳐 설계 #1 아키텍쳐 설계 방법론
대용량 분산 아키텍쳐 설계 #1 아키텍쳐 설계 방법론대용량 분산 아키텍쳐 설계 #1 아키텍쳐 설계 방법론
대용량 분산 아키텍쳐 설계 #1 아키텍쳐 설계 방법론Terry Cho
 
[Pgday.Seoul 2020] SQL Tuning
[Pgday.Seoul 2020] SQL Tuning[Pgday.Seoul 2020] SQL Tuning
[Pgday.Seoul 2020] SQL TuningPgDay.Seoul
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with SpringJoshua Long
 

What's hot (20)

Deep Dive into Apex Triggers
Deep Dive into Apex TriggersDeep Dive into Apex Triggers
Deep Dive into Apex Triggers
 
Salesforce Development Best Practices
Salesforce Development Best PracticesSalesforce Development Best Practices
Salesforce Development Best Practices
 
SFDC Batch Apex
SFDC Batch ApexSFDC Batch Apex
SFDC Batch Apex
 
ORM, JPA, & Hibernate Overview
ORM, JPA, & Hibernate OverviewORM, JPA, & Hibernate Overview
ORM, JPA, & Hibernate Overview
 
How to Analyze and Tune MySQL Queries for Better Performance
How to Analyze and Tune MySQL Queries for Better PerformanceHow to Analyze and Tune MySQL Queries for Better Performance
How to Analyze and Tune MySQL Queries for Better Performance
 
Apex Enterprise Patterns: Building Strong Foundations
Apex Enterprise Patterns: Building Strong FoundationsApex Enterprise Patterns: Building Strong Foundations
Apex Enterprise Patterns: Building Strong Foundations
 
Batchable vs @future vs Queueable
Batchable vs @future vs QueueableBatchable vs @future vs Queueable
Batchable vs @future vs Queueable
 
Oracle GoldenGate on Docker
Oracle GoldenGate on DockerOracle GoldenGate on Docker
Oracle GoldenGate on Docker
 
[Pgday.Seoul 2021] 1. 예제로 살펴보는 포스트그레스큐엘의 독특한 SQL
[Pgday.Seoul 2021] 1. 예제로 살펴보는 포스트그레스큐엘의 독특한 SQL[Pgday.Seoul 2021] 1. 예제로 살펴보는 포스트그레스큐엘의 독특한 SQL
[Pgday.Seoul 2021] 1. 예제로 살펴보는 포스트그레스큐엘의 독특한 SQL
 
Custom policies in mule 4 and a circuit breaker example
Custom policies in mule 4 and a circuit breaker exampleCustom policies in mule 4 and a circuit breaker example
Custom policies in mule 4 and a circuit breaker example
 
Oracle DB 19c: SQL Tuning Using SPM
Oracle DB 19c: SQL Tuning Using SPMOracle DB 19c: SQL Tuning Using SPM
Oracle DB 19c: SQL Tuning Using SPM
 
Stumbling stones when migrating from Oracle
 Stumbling stones when migrating from Oracle Stumbling stones when migrating from Oracle
Stumbling stones when migrating from Oracle
 
REST API Basics
REST API BasicsREST API Basics
REST API Basics
 
Development Best Practices
Development Best PracticesDevelopment Best Practices
Development Best Practices
 
Introduction to Apex Triggers
Introduction to Apex TriggersIntroduction to Apex Triggers
Introduction to Apex Triggers
 
Automate the operation of your Oracle Cloud infrastructure v2.0
Automate the operation of your Oracle Cloud infrastructure v2.0Automate the operation of your Oracle Cloud infrastructure v2.0
Automate the operation of your Oracle Cloud infrastructure v2.0
 
Alfresco tuning part1
Alfresco tuning part1Alfresco tuning part1
Alfresco tuning part1
 
대용량 분산 아키텍쳐 설계 #1 아키텍쳐 설계 방법론
대용량 분산 아키텍쳐 설계 #1 아키텍쳐 설계 방법론대용량 분산 아키텍쳐 설계 #1 아키텍쳐 설계 방법론
대용량 분산 아키텍쳐 설계 #1 아키텍쳐 설계 방법론
 
[Pgday.Seoul 2020] SQL Tuning
[Pgday.Seoul 2020] SQL Tuning[Pgday.Seoul 2020] SQL Tuning
[Pgday.Seoul 2020] SQL Tuning
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with Spring
 

Viewers also liked

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 ProblemsSalesforce Developers
 
Salesforce Presentation
Salesforce PresentationSalesforce Presentation
Salesforce PresentationChetna Purohit
 
Configuration tips
Configuration tipsConfiguration tips
Configuration tipsvraopolisetti
 
Apex triggers, force_ide_and_deployment
Apex triggers, force_ide_and_deploymentApex triggers, force_ide_and_deployment
Apex triggers, force_ide_and_deploymentsubhajit0209
 
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 ToolkitAndrew 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 BuilderKevin 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 ToolkitSalesforce Developers
 
Salesforce API: Salesforce Console Deep Dive
Salesforce API: Salesforce Console Deep DiveSalesforce API: Salesforce Console Deep Dive
Salesforce API: Salesforce Console Deep DiveSalesforce Developers
 
Approval process
Approval processApproval process
Approval processmallareddy0107
 
Getting started with Salesforce security
Getting started with Salesforce securityGetting started with Salesforce security
Getting started with Salesforce securitySalesforce Admins
 
Introduction to Salesforce validation rules new
Introduction to Salesforce validation rules newIntroduction to Salesforce validation rules new
Introduction to Salesforce validation rules newOmprakash Saini
 
Exposing Salesforce REST Services Using Swagger
Exposing Salesforce REST Services Using SwaggerExposing Salesforce REST Services Using Swagger
Exposing Salesforce REST Services Using SwaggerSalesforce 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 SalesforceMST 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 DiveSalesforce 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 OrgSalesforce Developers
 
Approvals and workflow in salesforce
Approvals and workflow in salesforceApprovals and workflow in salesforce
Approvals and workflow in salesforcemallareddy0107
 

Viewers also liked (20)

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 Presentation
Salesforce PresentationSalesforce Presentation
Salesforce Presentation
 
Configuration tips
Configuration tipsConfiguration tips
Configuration tips
 
Updating your user profile in communities
Updating your user profile in communitiesUpdating your user profile in communities
Updating your user profile in communities
 
Introduction to Apex Triggers
Introduction to Apex TriggersIntroduction to Apex Triggers
Introduction to Apex Triggers
 
Apex triggers, force_ide_and_deployment
Apex triggers, force_ide_and_deploymentApex triggers, force_ide_and_deployment
Apex triggers, force_ide_and_deployment
 
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
 
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
 
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 API: Salesforce Console Deep Dive
Salesforce API: Salesforce Console Deep DiveSalesforce API: Salesforce Console Deep Dive
Salesforce API: Salesforce Console Deep Dive
 
Approval process
Approval processApproval process
Approval process
 
Introduction to Apex Triggers
Introduction to Apex TriggersIntroduction to Apex Triggers
Introduction to Apex Triggers
 
Getting started with Salesforce security
Getting started with Salesforce securityGetting started with Salesforce security
Getting started with Salesforce security
 
Introduction to Salesforce validation rules new
Introduction to Salesforce validation rules newIntroduction to Salesforce validation rules new
Introduction to Salesforce validation rules new
 
Exposing Salesforce REST Services Using Swagger
Exposing Salesforce REST Services Using SwaggerExposing Salesforce REST Services Using Swagger
Exposing Salesforce REST Services Using Swagger
 
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...
 
Workflow in Salesforce
Workflow in SalesforceWorkflow in Salesforce
Workflow in Salesforce
 
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
 
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
 
Approvals and workflow in salesforce
Approvals and workflow in salesforceApprovals and workflow in salesforce
Approvals and workflow in salesforce
 

Similar to Triggers and order of execution1

salesforce triggers interview questions and answers
salesforce triggers interview questions and answerssalesforce triggers interview questions and answers
salesforce triggers interview questions and answersbhanuadmob
 
Qtp manual testing tutorials by QuontraSolutions
Qtp manual testing tutorials by QuontraSolutionsQtp manual testing tutorials by QuontraSolutions
Qtp manual testing tutorials by QuontraSolutionsQUONTRASOLUTIONS
 
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 TrainingJanBask 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 DevOpsAgileThought
 
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 trackingSonny56
 
Test Driven Development with Sql Server
Test Driven Development with Sql ServerTest Driven Development with Sql Server
Test Driven Development with Sql ServerDavid P. Moore
 
Large Data Volume Salesforce experiences
Large Data Volume Salesforce experiencesLarge Data Volume Salesforce experiences
Large Data Volume Salesforce experiencesCidar Mendizabal
 
Docker, Zabbix and auto-scaling
Docker, Zabbix and auto-scalingDocker, Zabbix and auto-scaling
Docker, Zabbix and auto-scalingVitaly Peregudov
 
Oracle data capture c dc
Oracle data capture c dcOracle data capture c dc
Oracle data capture c dcAmit Sharma
 
Intro to tsql unit 14
Intro to tsql   unit 14Intro to tsql   unit 14
Intro to tsql unit 14Syed Asrarali
 
Qtp Training
Qtp TrainingQtp Training
Qtp Trainingmehramit
 
Hybrid framework
Hybrid frameworkHybrid framework
Hybrid frameworkSudhakar 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 DimensionallyTeamstudio
 

Similar to Triggers and order of execution1 (20)

salesforce triggers interview questions and answers
salesforce triggers interview questions and answerssalesforce triggers interview questions and answers
salesforce triggers interview questions and answers
 
Salesforce testing best_practices
Salesforce testing best_practicesSalesforce testing best_practices
Salesforce testing best_practices
 
Qtp manual testing tutorials by QuontraSolutions
Qtp manual testing tutorials by QuontraSolutionsQtp manual testing tutorials by QuontraSolutions
Qtp manual testing tutorials by QuontraSolutions
 
Active database
Active databaseActive database
Active database
 
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
 
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
 
Custom Controllers and Controller Extensions
Custom Controllers and Controller Extensions Custom Controllers and Controller Extensions
Custom Controllers and Controller Extensions
 
Change tracking
Change trackingChange tracking
Change tracking
 
LDV.pptx
LDV.pptxLDV.pptx
LDV.pptx
 
Stored procedures
Stored proceduresStored procedures
Stored procedures
 
Test Driven Development with Sql Server
Test Driven Development with Sql ServerTest Driven Development with Sql Server
Test Driven Development with Sql Server
 
Large Data Volume Salesforce experiences
Large Data Volume Salesforce experiencesLarge Data Volume Salesforce experiences
Large Data Volume Salesforce experiences
 
Docker, Zabbix and auto-scaling
Docker, Zabbix and auto-scalingDocker, Zabbix and auto-scaling
Docker, Zabbix and auto-scaling
 
Data warehouse testing
Data warehouse testingData warehouse testing
Data warehouse testing
 
Oracle data capture c dc
Oracle data capture c dcOracle data capture c dc
Oracle data capture c dc
 
Intro to tsql unit 14
Intro to tsql   unit 14Intro to tsql   unit 14
Intro to tsql unit 14
 
Intro to tsql
Intro to tsqlIntro to tsql
Intro to tsql
 
Qtp Training
Qtp TrainingQtp Training
Qtp Training
 
Hybrid framework
Hybrid frameworkHybrid framework
Hybrid framework
 
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
 

Recently uploaded

Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseAnaAcapella
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 

Recently uploaded (20)

Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 

Triggers and order of execution1

  • 1.
  • 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.
  • 12.
  • 13. Triggers and Order of Execution