SlideShare uma empresa Scribd logo
1 de 22
Baixar para ler offline
Apex 10 Commandments

Francis Pindar, NetStronghold (UK)
@radnip

Kevin Poorman, Madrona Solutions Group
@codefriar
#1 Thou shalt not put queries in for loops
#1 Thou shalt not put queries in for loops
#2 Thou shalt not put DML in for loops
#2 Thou shalt not put DML in for loops
#3 Thou shalt have a happy balance
between clicks & code
▪ Triggers that replicate declarative functionality.
• Roll-up summary
• Workflows
• Email Templates
• Global Settings
• …

Good Salesforce Architectural Design
#4 Thou shalt only put one trigger per object
#5 Thou shalt not put code in triggers other than
calling methods and managing execution order
#6 Thou shalt utilize maps for queries wherever
possible
#7 Thou shalt make use of relationships to reduce
queries wherever possible
#8 Thou shalt aim for 100% test coverage
In general test your methods for:
▪ Positive effects.
• Given proper input it should act like this.
• Not just happy path, but all logic branches.

▪ Negative effects.
• Given bad data it should error like this.

▪ Role/Profile/User effects
• Given a user with X profile and Y role it should act like this.
#9 Thou shalt write meaningful and useful tests
It’s not a test without assertions.
▪ Assert(A==B, “Reason for Assert failure”)
▪ AssertEquals(A,B, “Reason for Assert failure”)
▪ AssertNotEquals(A,B, “Reason for Assert failure”)
#9 Thou shalt write meaningful and useful tests
Test with your own data
▪ Use Test.StartTest() / Test.StopTest()
#9 Thou shalt write meaningful and useful tests
Test one thing at a time
▪ Maintain Focus
▪ Just One Thing!
#10 Thou shalt limit future calls and use
asynchronous code where possible
In general bias towards batch apex
▪ Ensure it runs as efficiently as possible.
• Limit and tune time outs for callouts.
• Tune soql queries for efficiency – dev console can help here.

▪ If you need @future methods.
• Optimize them the same way you would optimize your batch apex.
• Resist methods that would queue many @future calls at once. (governor limits!)
Francis Pindar

Kevin Poorman

Technical Consultant
@radnip

Sr. Consultant
@codefriar
The Apex Ten Commandments

Mais conteúdo relacionado

Mais procurados

Shawn Wallace - Test automation in brownfield applications
Shawn Wallace - Test automation in brownfield applicationsShawn Wallace - Test automation in brownfield applications
Shawn Wallace - Test automation in brownfield applications
QA or the Highway
 
Unstoppable releases with kanban
Unstoppable releases with kanbanUnstoppable releases with kanban
Unstoppable releases with kanban
Andrii Shumada
 
FinalInnovationWeek-Dec12
FinalInnovationWeek-Dec12FinalInnovationWeek-Dec12
FinalInnovationWeek-Dec12
Praneet Mhatre
 

Mais procurados (19)

Test-Driven Design - ¿Porqué?
Test-Driven Design - ¿Porqué?Test-Driven Design - ¿Porqué?
Test-Driven Design - ¿Porqué?
 
Building Test Automations the agile way
Building Test Automations the agile way Building Test Automations the agile way
Building Test Automations the agile way
 
Future of Testing, Test Automation and The Quality Analyst
Future of Testing, Test Automation and The Quality AnalystFuture of Testing, Test Automation and The Quality Analyst
Future of Testing, Test Automation and The Quality Analyst
 
How to Go Codeless for Automated Mobile App Testing
How to Go Codeless for Automated Mobile App TestingHow to Go Codeless for Automated Mobile App Testing
How to Go Codeless for Automated Mobile App Testing
 
Episode 22 - Design Pattern 2
Episode 22 - Design Pattern 2Episode 22 - Design Pattern 2
Episode 22 - Design Pattern 2
 
Agile Project Management: "How I Learned to Stop Worrying and Love Agile”
Agile Project Management: "How I Learned to Stop Worrying and Love Agile”Agile Project Management: "How I Learned to Stop Worrying and Love Agile”
Agile Project Management: "How I Learned to Stop Worrying and Love Agile”
 
Shawn Wallace - Test automation in brownfield applications
Shawn Wallace - Test automation in brownfield applicationsShawn Wallace - Test automation in brownfield applications
Shawn Wallace - Test automation in brownfield applications
 
Agile Acceptance Criteria How To
Agile Acceptance Criteria How ToAgile Acceptance Criteria How To
Agile Acceptance Criteria How To
 
Developer Night - Opticon18
Developer Night - Opticon18Developer Night - Opticon18
Developer Night - Opticon18
 
Tdd2018 state of the software quality in Germany
Tdd2018 state of the software quality in GermanyTdd2018 state of the software quality in Germany
Tdd2018 state of the software quality in Germany
 
Practical service level objectives with error budgeting
Practical service level objectives with error budgetingPractical service level objectives with error budgeting
Practical service level objectives with error budgeting
 
[XPday.vn] Legacy code workshop (at) [XP Day Vietnam 2015]
[XPday.vn] Legacy code workshop (at) [XP Day Vietnam 2015][XPday.vn] Legacy code workshop (at) [XP Day Vietnam 2015]
[XPday.vn] Legacy code workshop (at) [XP Day Vietnam 2015]
 
Agile Mumbai 2020 Conference | How to get the best ROI on Your Test Automati...
Agile Mumbai 2020 Conference |  How to get the best ROI on Your Test Automati...Agile Mumbai 2020 Conference |  How to get the best ROI on Your Test Automati...
Agile Mumbai 2020 Conference | How to get the best ROI on Your Test Automati...
 
Why software projects fail in 2021?
Why software projects fail in 2021?Why software projects fail in 2021?
Why software projects fail in 2021?
 
Job manager 2020 in Angular
Job manager 2020 in AngularJob manager 2020 in Angular
Job manager 2020 in Angular
 
Boquet manager
Boquet managerBoquet manager
Boquet manager
 
Unstoppable releases with kanban
Unstoppable releases with kanbanUnstoppable releases with kanban
Unstoppable releases with kanban
 
FinalInnovationWeek-Dec12
FinalInnovationWeek-Dec12FinalInnovationWeek-Dec12
FinalInnovationWeek-Dec12
 
Innovation week dec12
Innovation week dec12Innovation week dec12
Innovation week dec12
 

Semelhante a The Apex Ten Commandments

Driving application development through behavior driven development
Driving application development through behavior driven developmentDriving application development through behavior driven development
Driving application development through behavior driven development
Einar Ingebrigtsen
 
The View - Lotusscript coding best practices
The View - Lotusscript coding best practicesThe View - Lotusscript coding best practices
The View - Lotusscript coding best practices
Bill Buchan
 
Computational thinking
Computational thinkingComputational thinking
Computational thinking
r123457
 
Dev buchan 30 proven tips
Dev buchan 30 proven tipsDev buchan 30 proven tips
Dev buchan 30 proven tips
Bill Buchan
 
Effective TDD - Less is more
Effective TDD - Less is moreEffective TDD - Less is more
Effective TDD - Less is more
Ben Lau
 
Twelve practices of XP_Se lect5 btech
Twelve practices of XP_Se lect5 btechTwelve practices of XP_Se lect5 btech
Twelve practices of XP_Se lect5 btech
IIITA
 
Behaviour drivendevelopment
Behaviour drivendevelopmentBehaviour drivendevelopment
Behaviour drivendevelopment
Young Alista
 
Behaviour driven development
Behaviour driven developmentBehaviour driven development
Behaviour driven development
Tony Nguyen
 
Behaviour driven development
Behaviour driven developmentBehaviour driven development
Behaviour driven development
James Wong
 
Behaviour drivendevelopment
Behaviour drivendevelopmentBehaviour drivendevelopment
Behaviour drivendevelopment
Luis Goldster
 

Semelhante a The Apex Ten Commandments (20)

Salesforce Apex Ten Commandments
Salesforce Apex Ten CommandmentsSalesforce Apex Ten Commandments
Salesforce Apex Ten Commandments
 
代码大全(内训)
代码大全(内训)代码大全(内训)
代码大全(内训)
 
Tips and tricks to win kaggle data science competitions
Tips and tricks to win kaggle data science competitionsTips and tricks to win kaggle data science competitions
Tips and tricks to win kaggle data science competitions
 
Driving application development through behavior driven development
Driving application development through behavior driven developmentDriving application development through behavior driven development
Driving application development through behavior driven development
 
The View - Lotusscript coding best practices
The View - Lotusscript coding best practicesThe View - Lotusscript coding best practices
The View - Lotusscript coding best practices
 
A Brief Introduction to Test-Driven Development
A Brief Introduction to Test-Driven DevelopmentA Brief Introduction to Test-Driven Development
A Brief Introduction to Test-Driven Development
 
Test Driven Development with Laravel
Test Driven Development with LaravelTest Driven Development with Laravel
Test Driven Development with Laravel
 
Software Craftmanship - Cours Polytech
Software Craftmanship - Cours PolytechSoftware Craftmanship - Cours Polytech
Software Craftmanship - Cours Polytech
 
Computational thinking
Computational thinkingComputational thinking
Computational thinking
 
Dev buchan 30 proven tips
Dev buchan 30 proven tipsDev buchan 30 proven tips
Dev buchan 30 proven tips
 
Effective TDD - Less is more
Effective TDD - Less is moreEffective TDD - Less is more
Effective TDD - Less is more
 
Reading Notes : the practice of programming
Reading Notes : the practice of programmingReading Notes : the practice of programming
Reading Notes : the practice of programming
 
Designing REST APIs
Designing REST APIsDesigning REST APIs
Designing REST APIs
 
Software development best practices & coding guidelines
Software development best practices & coding guidelinesSoftware development best practices & coding guidelines
Software development best practices & coding guidelines
 
Twelve practices of XP_Se lect5 btech
Twelve practices of XP_Se lect5 btechTwelve practices of XP_Se lect5 btech
Twelve practices of XP_Se lect5 btech
 
Behaviour drivendevelopment
Behaviour drivendevelopmentBehaviour drivendevelopment
Behaviour drivendevelopment
 
Behaviour driven development
Behaviour driven developmentBehaviour driven development
Behaviour driven development
 
Behaviour driven development
Behaviour driven developmentBehaviour driven development
Behaviour driven development
 
Behaviour drivendevelopment
Behaviour drivendevelopmentBehaviour drivendevelopment
Behaviour drivendevelopment
 
Behaviour drivendevelopment
Behaviour drivendevelopmentBehaviour drivendevelopment
Behaviour drivendevelopment
 

Mais de Salesforce Developers

Mais de Salesforce Developers (20)

Sample Gallery: Reference Code and Best Practices for Salesforce Developers
Sample Gallery: Reference Code and Best Practices for Salesforce DevelopersSample Gallery: Reference Code and Best Practices for Salesforce Developers
Sample Gallery: Reference Code and Best Practices for Salesforce Developers
 
Maximizing Salesforce Lightning Experience and Lightning Component Performance
Maximizing Salesforce Lightning Experience and Lightning Component PerformanceMaximizing Salesforce Lightning Experience and Lightning Component Performance
Maximizing Salesforce Lightning Experience and Lightning Component Performance
 
Local development with Open Source Base Components
Local development with Open Source Base ComponentsLocal development with Open Source Base Components
Local development with Open Source Base Components
 
TrailheaDX India : Developer Highlights
TrailheaDX India : Developer HighlightsTrailheaDX India : Developer Highlights
TrailheaDX India : Developer Highlights
 
Why developers shouldn’t miss TrailheaDX India
Why developers shouldn’t miss TrailheaDX IndiaWhy developers shouldn’t miss TrailheaDX India
Why developers shouldn’t miss TrailheaDX India
 
CodeLive: Build Lightning Web Components faster with Local Development
CodeLive: Build Lightning Web Components faster with Local DevelopmentCodeLive: Build Lightning Web Components faster with Local Development
CodeLive: Build Lightning Web Components faster with Local Development
 
CodeLive: Converting Aura Components to Lightning Web Components
CodeLive: Converting Aura Components to Lightning Web ComponentsCodeLive: Converting Aura Components to Lightning Web Components
CodeLive: Converting Aura Components to Lightning Web Components
 
Enterprise-grade UI with open source Lightning Web Components
Enterprise-grade UI with open source Lightning Web ComponentsEnterprise-grade UI with open source Lightning Web Components
Enterprise-grade UI with open source Lightning Web Components
 
TrailheaDX and Summer '19: Developer Highlights
TrailheaDX and Summer '19: Developer HighlightsTrailheaDX and Summer '19: Developer Highlights
TrailheaDX and Summer '19: Developer Highlights
 
Live coding with LWC
Live coding with LWCLive coding with LWC
Live coding with LWC
 
Lightning web components - Episode 4 : Security and Testing
Lightning web components  - Episode 4 : Security and TestingLightning web components  - Episode 4 : Security and Testing
Lightning web components - Episode 4 : Security and Testing
 
LWC Episode 3- Component Communication and Aura Interoperability
LWC Episode 3- Component Communication and Aura InteroperabilityLWC Episode 3- Component Communication and Aura Interoperability
LWC Episode 3- Component Communication and Aura Interoperability
 
Lightning web components episode 2- work with salesforce data
Lightning web components   episode 2- work with salesforce dataLightning web components   episode 2- work with salesforce data
Lightning web components episode 2- work with salesforce data
 
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
 
Migrating CPQ to Advanced Calculator and JSQCP
Migrating CPQ to Advanced Calculator and JSQCPMigrating CPQ to Advanced Calculator and JSQCP
Migrating CPQ to Advanced Calculator and JSQCP
 
Scale with Large Data Volumes and Big Objects in Salesforce
Scale with Large Data Volumes and Big Objects in SalesforceScale with Large Data Volumes and Big Objects in Salesforce
Scale with Large Data Volumes and Big Objects in Salesforce
 
Replicate Salesforce Data in Real Time with Change Data Capture
Replicate Salesforce Data in Real Time with Change Data CaptureReplicate Salesforce Data in Real Time with Change Data Capture
Replicate Salesforce Data in Real Time with Change Data Capture
 
Modern Development with Salesforce DX
Modern Development with Salesforce DXModern Development with Salesforce DX
Modern Development with Salesforce DX
 
Get Into Lightning Flow Development
Get Into Lightning Flow DevelopmentGet Into Lightning Flow Development
Get Into Lightning Flow Development
 
Integrate CMS Content Into Lightning Communities with CMS Connect
Integrate CMS Content Into Lightning Communities with CMS ConnectIntegrate CMS Content Into Lightning Communities with CMS Connect
Integrate CMS Content Into Lightning Communities with CMS Connect
 

Último

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Último (20)

Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 

The Apex Ten Commandments

  • 1. Apex 10 Commandments Francis Pindar, NetStronghold (UK) @radnip Kevin Poorman, Madrona Solutions Group @codefriar
  • 2.
  • 3. #1 Thou shalt not put queries in for loops
  • 4. #1 Thou shalt not put queries in for loops
  • 5. #2 Thou shalt not put DML in for loops
  • 6. #2 Thou shalt not put DML in for loops
  • 7.
  • 8. #3 Thou shalt have a happy balance between clicks & code ▪ Triggers that replicate declarative functionality. • Roll-up summary • Workflows • Email Templates • Global Settings • … Good Salesforce Architectural Design
  • 9. #4 Thou shalt only put one trigger per object
  • 10. #5 Thou shalt not put code in triggers other than calling methods and managing execution order
  • 11. #6 Thou shalt utilize maps for queries wherever possible
  • 12. #7 Thou shalt make use of relationships to reduce queries wherever possible
  • 13. #8 Thou shalt aim for 100% test coverage In general test your methods for: ▪ Positive effects. • Given proper input it should act like this. • Not just happy path, but all logic branches. ▪ Negative effects. • Given bad data it should error like this. ▪ Role/Profile/User effects • Given a user with X profile and Y role it should act like this.
  • 14.
  • 15.
  • 16.
  • 17. #9 Thou shalt write meaningful and useful tests It’s not a test without assertions. ▪ Assert(A==B, “Reason for Assert failure”) ▪ AssertEquals(A,B, “Reason for Assert failure”) ▪ AssertNotEquals(A,B, “Reason for Assert failure”)
  • 18. #9 Thou shalt write meaningful and useful tests Test with your own data ▪ Use Test.StartTest() / Test.StopTest()
  • 19. #9 Thou shalt write meaningful and useful tests Test one thing at a time ▪ Maintain Focus ▪ Just One Thing!
  • 20. #10 Thou shalt limit future calls and use asynchronous code where possible In general bias towards batch apex ▪ Ensure it runs as efficiently as possible. • Limit and tune time outs for callouts. • Tune soql queries for efficiency – dev console can help here. ▪ If you need @future methods. • Optimize them the same way you would optimize your batch apex. • Resist methods that would queue many @future calls at once. (governor limits!)
  • 21. Francis Pindar Kevin Poorman Technical Consultant @radnip Sr. Consultant @codefriar