SlideShare ist ein Scribd-Unternehmen logo
1 von 9
Apex Triggers & Scheduler Frameworks
By
Sumitkumar Shingavi
@sumit.shingavi
Agenda
 Design discussion on
 Apex Trigger
 Batches / Schedulers
 Open house : Share your experience!
 Twitter handlers: @sumit.shingavi @Prasanna
@thisisnotapril @salesforceDevs @TheChrisDuarte
@kevindrapatel
Few Questions : Apex Triggers
 When to use apex triggers?
 When to use before / after trigger?
 How many triggers you have built so far?
 What is the pattern of code you have used?
 What is batch size a trigger can handle when
bulkified?
 Do you ever seen a need to de-activate your triggers
during historic data migration for enterprise scale
projects?
3 ways to write Apex triggers?
 Modular Programming Approach – Simplest! (70%)
 Factory Pattern (20%)
 Abstraction of Handlers (10%)
 When there are multiple handlers for a object
 Sequencing of handlers is required in execution
 Dynamic instance creation is required.
 CustomSettings__c cs = CustomSettings__c.getInstance('Vehicle');
 Type t = Type.forName(cs.className__c);
 Vehicle v = (Vehicle) t.newInstance();
Apex Triggers – Keep it Simple!
 ONE trigger per object
 Logic – less triggers
 Context specific handler methods
 Use advance inline queried for loops wherever possible
 Right naming conventions
 Entry criteria – No open entry points / method calls!
 For Modular Programming approach, follow structure as:
 AccountTrigger
 AccountTriggerHandler
 AccountTriggerActions
 AccountTriggerTest
 For code visit: https://cloudmastro.blogspot.com
Factory & Abstraction of Handlers
 Factory pattern
 You should have an interface which declares all handler
virtual methods
 Handlers are instantiated dynamically
 When it actual goes down, you need to pass 1 object at a
time by iterating over List<sObject>
 Abstractions of handlers
 Also called as Dispatcher pattern
 Used when you want heavy segregation between your
events
 Difficult to maintain
Advantages of Proposed Framework
 Order of execution
 Separation of concerns
 Control over re-entrant code
 Clear organization and structure
 Singleton frame
 Make implementing new logic very easy
 Simplify testing and maintenance
 What not to do!
 Do not use static variables to control re-entrant code
Apex Scheduled Batch Apex : Quick Highs
 You can have a single class Schedulable and Batchable
 Default batch size is 200 but can be raised up to 2000
 It is asynchronous so no guarantee on time
 100 scheduled apex jobs at a time
 While writing unit tests; you should put asserts after
Test.stopTest()
 Governor limits applied separately for batch and schedule
 10 webservice callouts per batch
 Database.stateful, Apex Flex Queue (100 jobs in one shot)
 Serial Batches: For this, you need to call next batch in
final() method of current batch.
Thank you!
Blog:
https://cloudmastro.blogspot.com
Twitter: @sumit.shingavi
Linkedin: Sumitkumar Shingavi

Weitere ähnliche Inhalte

Was ist angesagt?

Triggers and order of execution1
Triggers and order of execution1Triggers and order of execution1
Triggers and order of execution1Prabhakar Sharma
 
Process builder vs Triggers
Process builder vs TriggersProcess builder vs Triggers
Process builder vs TriggersProQuest
 
Episode 12 - Basics of Trigger
Episode 12 - Basics of TriggerEpisode 12 - Basics of Trigger
Episode 12 - Basics of TriggerJitendra Zaa
 
Five Enterprise Best Practices That EVERY Salesforce Org Can Use (DF15 Session)
Five Enterprise Best Practices That EVERY Salesforce Org Can Use (DF15 Session)Five Enterprise Best Practices That EVERY Salesforce Org Can Use (DF15 Session)
Five Enterprise Best Practices That EVERY Salesforce Org Can Use (DF15 Session)Vivek Chawla
 
Episode 20 - Trigger Frameworks in Salesforce
Episode 20 - Trigger Frameworks in SalesforceEpisode 20 - Trigger Frameworks in Salesforce
Episode 20 - Trigger Frameworks in SalesforceJitendra Zaa
 
Episode 5 - Writing unit tests in Salesforce
Episode 5 - Writing unit tests in SalesforceEpisode 5 - Writing unit tests in Salesforce
Episode 5 - Writing unit tests in SalesforceJitendra Zaa
 
Test & Dynamics CRM - extremeCRM Berlin 2012
Test & Dynamics CRM - extremeCRM Berlin 2012Test & Dynamics CRM - extremeCRM Berlin 2012
Test & Dynamics CRM - extremeCRM Berlin 2012Wael Hamze
 
Episode 13 - Advanced Apex Triggers
Episode 13 - Advanced Apex TriggersEpisode 13 - Advanced Apex Triggers
Episode 13 - Advanced Apex TriggersJitendra Zaa
 
SF1 - Apex Development Best Practises
SF1 - Apex Development Best PractisesSF1 - Apex Development Best Practises
SF1 - Apex Development Best PractisesSebastian Wagner
 
Continuous Integration In The Cloud Final (1)
Continuous Integration In The Cloud Final (1)Continuous Integration In The Cloud Final (1)
Continuous Integration In The Cloud Final (1)Alexis Williams
 
Integration Testing in AEM
Integration Testing in AEMIntegration Testing in AEM
Integration Testing in AEMconnectwebex
 
Advanced Testing and Debugging using the Developer Console webinar
Advanced Testing and Debugging using the Developer Console webinarAdvanced Testing and Debugging using the Developer Console webinar
Advanced Testing and Debugging using the Developer Console webinarSalesforce Developers
 
Testing CRM from a 360 View - extremeCRM Rome 2013
Testing CRM from a 360 View - extremeCRM Rome 2013Testing CRM from a 360 View - extremeCRM Rome 2013
Testing CRM from a 360 View - extremeCRM Rome 2013Wael Hamze
 
Building Test Automations the agile way
Building Test Automations the agile way Building Test Automations the agile way
Building Test Automations the agile way MakeMyTrip.com
 
Client-Side Performance Testing
Client-Side Performance TestingClient-Side Performance Testing
Client-Side Performance TestingAnand Bagmar
 
5 Secret Weapons Of A Great Salesforce Architect
5 Secret Weapons Of A Great Salesforce Architect5 Secret Weapons Of A Great Salesforce Architect
5 Secret Weapons Of A Great Salesforce ArchitectSebastian Wagner
 

Was ist angesagt? (20)

Triggers and order of execution1
Triggers and order of execution1Triggers and order of execution1
Triggers and order of execution1
 
Salesforce asynchronous apex
Salesforce asynchronous apexSalesforce asynchronous apex
Salesforce asynchronous apex
 
Process builder vs Triggers
Process builder vs TriggersProcess builder vs Triggers
Process builder vs Triggers
 
Episode 12 - Basics of Trigger
Episode 12 - Basics of TriggerEpisode 12 - Basics of Trigger
Episode 12 - Basics of Trigger
 
Five Enterprise Best Practices That EVERY Salesforce Org Can Use (DF15 Session)
Five Enterprise Best Practices That EVERY Salesforce Org Can Use (DF15 Session)Five Enterprise Best Practices That EVERY Salesforce Org Can Use (DF15 Session)
Five Enterprise Best Practices That EVERY Salesforce Org Can Use (DF15 Session)
 
Episode 20 - Trigger Frameworks in Salesforce
Episode 20 - Trigger Frameworks in SalesforceEpisode 20 - Trigger Frameworks in Salesforce
Episode 20 - Trigger Frameworks in Salesforce
 
Episode 5 - Writing unit tests in Salesforce
Episode 5 - Writing unit tests in SalesforceEpisode 5 - Writing unit tests in Salesforce
Episode 5 - Writing unit tests in Salesforce
 
Test & Dynamics CRM - extremeCRM Berlin 2012
Test & Dynamics CRM - extremeCRM Berlin 2012Test & Dynamics CRM - extremeCRM Berlin 2012
Test & Dynamics CRM - extremeCRM Berlin 2012
 
Episode 13 - Advanced Apex Triggers
Episode 13 - Advanced Apex TriggersEpisode 13 - Advanced Apex Triggers
Episode 13 - Advanced Apex Triggers
 
05 managing transactions
05   managing transactions05   managing transactions
05 managing transactions
 
SF1 - Apex Development Best Practises
SF1 - Apex Development Best PractisesSF1 - Apex Development Best Practises
SF1 - Apex Development Best Practises
 
Continuous Integration In The Cloud Final (1)
Continuous Integration In The Cloud Final (1)Continuous Integration In The Cloud Final (1)
Continuous Integration In The Cloud Final (1)
 
Workflow in Salesforce
Workflow in SalesforceWorkflow in Salesforce
Workflow in Salesforce
 
Integration Testing in AEM
Integration Testing in AEMIntegration Testing in AEM
Integration Testing in AEM
 
Advanced Testing and Debugging using the Developer Console webinar
Advanced Testing and Debugging using the Developer Console webinarAdvanced Testing and Debugging using the Developer Console webinar
Advanced Testing and Debugging using the Developer Console webinar
 
Testing CRM from a 360 View - extremeCRM Rome 2013
Testing CRM from a 360 View - extremeCRM Rome 2013Testing CRM from a 360 View - extremeCRM Rome 2013
Testing CRM from a 360 View - extremeCRM Rome 2013
 
Building Test Automations the agile way
Building Test Automations the agile way Building Test Automations the agile way
Building Test Automations the agile way
 
A Story of Continuous Integration
A Story of Continuous IntegrationA Story of Continuous Integration
A Story of Continuous Integration
 
Client-Side Performance Testing
Client-Side Performance TestingClient-Side Performance Testing
Client-Side Performance Testing
 
5 Secret Weapons Of A Great Salesforce Architect
5 Secret Weapons Of A Great Salesforce Architect5 Secret Weapons Of A Great Salesforce Architect
5 Secret Weapons Of A Great Salesforce Architect
 

Ähnlich wie Salesforce Meetup 18 April 2015 - Apex Trigger & Scheduler Framworks

Flex 4.5 jeyasekar
Flex 4.5  jeyasekarFlex 4.5  jeyasekar
Flex 4.5 jeyasekarjeya soft
 
Performance eng prakash.sahu
Performance eng prakash.sahuPerformance eng prakash.sahu
Performance eng prakash.sahuDr. Prakash Sahu
 
Salesforce Apex Hours :- Hyper batch
Salesforce Apex Hours :- Hyper batchSalesforce Apex Hours :- Hyper batch
Salesforce Apex Hours :- Hyper batchAmit Chaudhary
 
WinOps Conf 2016 - Michael Greene - Release Pipelines
WinOps Conf 2016 - Michael Greene - Release PipelinesWinOps Conf 2016 - Michael Greene - Release Pipelines
WinOps Conf 2016 - Michael Greene - Release PipelinesWinOps Conf
 
El camino a las Cloud Native Apps - Introduction
El camino a las Cloud Native Apps - IntroductionEl camino a las Cloud Native Apps - Introduction
El camino a las Cloud Native Apps - IntroductionPlain Concepts
 
Salesforce Summer 14 Release
Salesforce Summer 14 ReleaseSalesforce Summer 14 Release
Salesforce Summer 14 ReleaseJyothylakshmy P.U
 
Qtp interview questions
Qtp interview questionsQtp interview questions
Qtp interview questionsRamu Palanki
 
Qtp interview questions
Qtp interview questionsQtp interview questions
Qtp interview questionsRamu Palanki
 
What's New in .Net 4.5
What's New in .Net 4.5What's New in .Net 4.5
What's New in .Net 4.5Malam Team
 
Actionable Insights with Apache Apex at Apache Big Data 2017 by Devendra Tagare
Actionable Insights with Apache Apex at Apache Big Data 2017 by Devendra TagareActionable Insights with Apache Apex at Apache Big Data 2017 by Devendra Tagare
Actionable Insights with Apache Apex at Apache Big Data 2017 by Devendra TagareApache Apex
 
Cerberus : Framework for Manual and Automated Testing (Web Application)
Cerberus : Framework for Manual and Automated Testing (Web Application)Cerberus : Framework for Manual and Automated Testing (Web Application)
Cerberus : Framework for Manual and Automated Testing (Web Application)CIVEL Benoit
 
Cerberus_Presentation1
Cerberus_Presentation1Cerberus_Presentation1
Cerberus_Presentation1CIVEL Benoit
 
Building Continuous Application with Structured Streaming and Real-Time Data ...
Building Continuous Application with Structured Streaming and Real-Time Data ...Building Continuous Application with Structured Streaming and Real-Time Data ...
Building Continuous Application with Structured Streaming and Real-Time Data ...Databricks
 

Ähnlich wie Salesforce Meetup 18 April 2015 - Apex Trigger & Scheduler Framworks (20)

Flex 4.5 jeyasekar
Flex 4.5  jeyasekarFlex 4.5  jeyasekar
Flex 4.5 jeyasekar
 
Performance eng prakash.sahu
Performance eng prakash.sahuPerformance eng prakash.sahu
Performance eng prakash.sahu
 
Salesforce Apex Hours :- Hyper batch
Salesforce Apex Hours :- Hyper batchSalesforce Apex Hours :- Hyper batch
Salesforce Apex Hours :- Hyper batch
 
Javascript
JavascriptJavascript
Javascript
 
WinOps Conf 2016 - Michael Greene - Release Pipelines
WinOps Conf 2016 - Michael Greene - Release PipelinesWinOps Conf 2016 - Michael Greene - Release Pipelines
WinOps Conf 2016 - Michael Greene - Release Pipelines
 
El camino a las Cloud Native Apps - Introduction
El camino a las Cloud Native Apps - IntroductionEl camino a las Cloud Native Apps - Introduction
El camino a las Cloud Native Apps - Introduction
 
Production-ready Software
Production-ready SoftwareProduction-ready Software
Production-ready Software
 
Deploying Models
Deploying ModelsDeploying Models
Deploying Models
 
Asynchronous apex
Asynchronous apexAsynchronous apex
Asynchronous apex
 
Salesforce Summer 14 Release
Salesforce Summer 14 ReleaseSalesforce Summer 14 Release
Salesforce Summer 14 Release
 
Typesafe spark- Zalando meetup
Typesafe spark- Zalando meetupTypesafe spark- Zalando meetup
Typesafe spark- Zalando meetup
 
Qtp interview questions
Qtp interview questionsQtp interview questions
Qtp interview questions
 
Qtp interview questions
Qtp interview questionsQtp interview questions
Qtp interview questions
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
North east user group tour
North east user group tourNorth east user group tour
North east user group tour
 
What's New in .Net 4.5
What's New in .Net 4.5What's New in .Net 4.5
What's New in .Net 4.5
 
Actionable Insights with Apache Apex at Apache Big Data 2017 by Devendra Tagare
Actionable Insights with Apache Apex at Apache Big Data 2017 by Devendra TagareActionable Insights with Apache Apex at Apache Big Data 2017 by Devendra Tagare
Actionable Insights with Apache Apex at Apache Big Data 2017 by Devendra Tagare
 
Cerberus : Framework for Manual and Automated Testing (Web Application)
Cerberus : Framework for Manual and Automated Testing (Web Application)Cerberus : Framework for Manual and Automated Testing (Web Application)
Cerberus : Framework for Manual and Automated Testing (Web Application)
 
Cerberus_Presentation1
Cerberus_Presentation1Cerberus_Presentation1
Cerberus_Presentation1
 
Building Continuous Application with Structured Streaming and Real-Time Data ...
Building Continuous Application with Structured Streaming and Real-Time Data ...Building Continuous Application with Structured Streaming and Real-Time Data ...
Building Continuous Application with Structured Streaming and Real-Time Data ...
 

Kürzlich hochgeladen

How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 

Kürzlich hochgeladen (20)

How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 

Salesforce Meetup 18 April 2015 - Apex Trigger & Scheduler Framworks

  • 1. Apex Triggers & Scheduler Frameworks By Sumitkumar Shingavi @sumit.shingavi
  • 2. Agenda  Design discussion on  Apex Trigger  Batches / Schedulers  Open house : Share your experience!  Twitter handlers: @sumit.shingavi @Prasanna @thisisnotapril @salesforceDevs @TheChrisDuarte @kevindrapatel
  • 3. Few Questions : Apex Triggers  When to use apex triggers?  When to use before / after trigger?  How many triggers you have built so far?  What is the pattern of code you have used?  What is batch size a trigger can handle when bulkified?  Do you ever seen a need to de-activate your triggers during historic data migration for enterprise scale projects?
  • 4. 3 ways to write Apex triggers?  Modular Programming Approach – Simplest! (70%)  Factory Pattern (20%)  Abstraction of Handlers (10%)  When there are multiple handlers for a object  Sequencing of handlers is required in execution  Dynamic instance creation is required.  CustomSettings__c cs = CustomSettings__c.getInstance('Vehicle');  Type t = Type.forName(cs.className__c);  Vehicle v = (Vehicle) t.newInstance();
  • 5. Apex Triggers – Keep it Simple!  ONE trigger per object  Logic – less triggers  Context specific handler methods  Use advance inline queried for loops wherever possible  Right naming conventions  Entry criteria – No open entry points / method calls!  For Modular Programming approach, follow structure as:  AccountTrigger  AccountTriggerHandler  AccountTriggerActions  AccountTriggerTest  For code visit: https://cloudmastro.blogspot.com
  • 6. Factory & Abstraction of Handlers  Factory pattern  You should have an interface which declares all handler virtual methods  Handlers are instantiated dynamically  When it actual goes down, you need to pass 1 object at a time by iterating over List<sObject>  Abstractions of handlers  Also called as Dispatcher pattern  Used when you want heavy segregation between your events  Difficult to maintain
  • 7. Advantages of Proposed Framework  Order of execution  Separation of concerns  Control over re-entrant code  Clear organization and structure  Singleton frame  Make implementing new logic very easy  Simplify testing and maintenance  What not to do!  Do not use static variables to control re-entrant code
  • 8. Apex Scheduled Batch Apex : Quick Highs  You can have a single class Schedulable and Batchable  Default batch size is 200 but can be raised up to 2000  It is asynchronous so no guarantee on time  100 scheduled apex jobs at a time  While writing unit tests; you should put asserts after Test.stopTest()  Governor limits applied separately for batch and schedule  10 webservice callouts per batch  Database.stateful, Apex Flex Queue (100 jobs in one shot)  Serial Batches: For this, you need to call next batch in final() method of current batch.