SlideShare a Scribd company logo
1 of 29
Apex Development Best Practices
http://bit.ly/sf1-dev-bp
Sebastian Wagner, @tquiladotcom, Technical Architect
@seb__wagner
“I cannot teach anybody anything,
I can only make them think”
Socrates
Agenda
 Principles
 Process
 Development
– Conventions
– Queries
– Loops
– Tests
 QA
Process
 track requirements
 separate development sandboxes
 use source control (git, Mercury, SVN)
 automate deployment with CI
 iterate
Requirements
 Understand
– What is expected?
– Why, what are the drivers?
 Think
– How to implement?
– Impact, Dependencies
 Challenge
– Can it be flexed, to match platform features?
Platform Advantages
 Config over Code
– workflows instead of triggers
– Page Layout vs. Visualforce
 Native over Custom
– standard instead of custom objects
– re-label field
 Install/Deploy over Build
– AppExchange
– Github
XP Principles
 MVP - Minimum Viable Product (80/20 rule)
– focus on the core features
 KISS - Keep It Simple & Stupid
– the simplest solution to meet the requirement
– easy to use, read and change. looks simple
 DRY – Don’t Repeat Yourself
– Components, Labels, Templates, Abstraction, Service Classes
 YAGNI – You Arent Gonna Need It
– implement only WHEN you actually need it
DEV – Structure
The structure of code and config is clear and
understandable
 be consistent
 use a naming convention
 self describing names
 declare constants and literal values in variable or config
DEV – Comments
Loops and more complex parts of the algorithms are clear
and commented
 clear code (what) over comments (why)
 provide context and help understanding
 describe purpose of classes and methods
 do NOT comment trivial code
DEV – Error Handling
Exceptions and errors are managed using
exception handling
 catch in user facing code (e.g. in trigger or controller)
 provide useful description if necessary
 descriptive error messages
 do NOT catch exceptions in service methods,
unless you return your own error object
DEV – Error Handling
 insert Account Deactivation Handler
 https://gist.github.com/sebwagner/5e556d492fa2cc010d
c9
Query - Conditions
All SOQL queries are appropriately restricted by a WHERE
clause or a LIMIT parameter
 filter records by SOQL rather than code
 use of indexes (Id, Text, Number) whenever possible
 follows best practices for Query Optimizer (e.g. avoid to
filter on NULL)
Query - Conditions
Query – Efficiency
Efficient use of queries for good performance
 cache records for re-use in context
 avoid querying the same object multiple times
 exclude fields that are not needed
 lazy load Blob and Large Text fields
Query – Efficiency
Loops - Limits
Beware of the Governor Limits
 loops (for, do-while) do NOT invoke
– SOSL/SOQL statements
– DML statements
 method calls which use limits are not invoked in loops
where avoidable e.g. Describes, Callouts, sendEmail()
Loops - Limits
Testing – Code Coverage
Code coverage is no lower than 90%. yet it is not
everything, but
 high coverage => less bugs => less frustration
 keep testability in mind when writing code, because
 if you can’t test it, it's an indicator for Code Smell
Testing – Code Coverage ‘Alternative’
Testing – Test Data
Tests setup their own test data
@isTest(seeAllData=false)
 do NOT rely on organization data
 if org data is need, limit to methods
 use test data classes or methods for re-use
Testing – Test Data
Testing – Test Data
Testing - Assertions
Assertions are used to validate expected results
 true testing, validation rather than only execution
 +1 assert per test method
 use the message parameter to provide context
system.assert(Object,Object,message);
Testing - Assertions
Testing - Scenarios
Tests validate positive and negative outcomes
 Positive: execution with valid data / params
 Negative: execution with invalid data / params
 use system.runAs() to test
– Dynamic Apex
– Methods using with sharing or without sharing
– Shared records
Testing - Scenarios
Testing – Bulk Tests
Code should be bulkified, so should be the tests
 ensures you don’t hit governor limits
 can uncover performance bottlenecks
Testing – Bulk Tests
Thank you
http://bit.ly/sf1-dev-bp
Sebastian Wagner, @tquiladotcom, Technical Architect
@seb__wagner

More Related Content

What's hot

Release Management: Managing Your Internal Releases
Release Management: Managing Your Internal ReleasesRelease Management: Managing Your Internal Releases
Release Management: Managing Your Internal ReleasesJoshua Hoskins
 
5 Essentials for Simplifiied Release Management and Continuous Delivery
5 Essentials for Simplifiied Release Management and Continuous Delivery5 Essentials for Simplifiied Release Management and Continuous Delivery
5 Essentials for Simplifiied Release Management and Continuous DeliverySalesforce Developers
 
Design patterns for salesforce app decomposition
Design patterns for salesforce app decompositionDesign patterns for salesforce app decomposition
Design patterns for salesforce app decompositionSai Jithesh ☁️
 
Follow the evidence: Troubleshooting Performance Issues
Follow the evidence:  Troubleshooting Performance IssuesFollow the evidence:  Troubleshooting Performance Issues
Follow the evidence: Troubleshooting Performance IssuesSalesforce Developers
 
How Open Source Embiggens Salesforce.com
How Open Source Embiggens Salesforce.comHow Open Source Embiggens Salesforce.com
How Open Source Embiggens Salesforce.comSalesforce Engineering
 
Salesforce Lightning Process builder
Salesforce Lightning Process builderSalesforce Lightning Process builder
Salesforce Lightning Process builderThinqloud
 
Managing Change With A Sensible Sandbox Architecture
Managing Change With A Sensible Sandbox ArchitectureManaging Change With A Sensible Sandbox Architecture
Managing Change With A Sensible Sandbox ArchitectureAlexander Sutherland
 
Testing Web Apps and APIs (1)
Testing Web Apps and APIs (1)Testing Web Apps and APIs (1)
Testing Web Apps and APIs (1)AAron EvaNS
 
Continuous test automation
Continuous test automationContinuous test automation
Continuous test automationMacharla Pradeep
 
Salesforce.com Sandbox management
Salesforce.com Sandbox management Salesforce.com Sandbox management
Salesforce.com Sandbox management Ali Akbar
 
Salesforce1 ELEVATE Workshop - Dublin
Salesforce1 ELEVATE Workshop - DublinSalesforce1 ELEVATE Workshop - Dublin
Salesforce1 ELEVATE Workshop - DublinJoshua Hoskins
 
TDX19 - Accelerate DevOps with GitLab and Salesforce
TDX19 - Accelerate DevOps with GitLab and SalesforceTDX19 - Accelerate DevOps with GitLab and Salesforce
TDX19 - Accelerate DevOps with GitLab and SalesforceDoug Ayers
 
Manage Development in Your Org with Salesforce Governance Framework
Manage Development in Your Org with Salesforce Governance FrameworkManage Development in Your Org with Salesforce Governance Framework
Manage Development in Your Org with Salesforce Governance FrameworkSalesforce Developers
 
FSL Implementation Guidance Part 1
FSL Implementation Guidance Part 1FSL Implementation Guidance Part 1
FSL Implementation Guidance Part 1Salesforce Partners
 
Discover salesforce, dev ops and Copado CI/CD automations
Discover salesforce, dev ops and Copado CI/CD automationsDiscover salesforce, dev ops and Copado CI/CD automations
Discover salesforce, dev ops and Copado CI/CD automationsJackGuo20
 
Salesforce Release Management - Best Practices and Tools for Deployment
Salesforce Release Management - Best Practices and Tools for DeploymentSalesforce Release Management - Best Practices and Tools for Deployment
Salesforce Release Management - Best Practices and Tools for DeploymentSalesforce Developers
 

What's hot (20)

Release Management: Managing Your Internal Releases
Release Management: Managing Your Internal ReleasesRelease Management: Managing Your Internal Releases
Release Management: Managing Your Internal Releases
 
5 Essentials for Simplifiied Release Management and Continuous Delivery
5 Essentials for Simplifiied Release Management and Continuous Delivery5 Essentials for Simplifiied Release Management and Continuous Delivery
5 Essentials for Simplifiied Release Management and Continuous Delivery
 
Under the Hood of Sandbox Templates
Under the Hood of Sandbox TemplatesUnder the Hood of Sandbox Templates
Under the Hood of Sandbox Templates
 
Design patterns for salesforce app decomposition
Design patterns for salesforce app decompositionDesign patterns for salesforce app decomposition
Design patterns for salesforce app decomposition
 
Introduction to Apex Triggers
Introduction to Apex TriggersIntroduction to Apex Triggers
Introduction to Apex Triggers
 
Follow the evidence: Troubleshooting Performance Issues
Follow the evidence:  Troubleshooting Performance IssuesFollow the evidence:  Troubleshooting Performance Issues
Follow the evidence: Troubleshooting Performance Issues
 
How Open Source Embiggens Salesforce.com
How Open Source Embiggens Salesforce.comHow Open Source Embiggens Salesforce.com
How Open Source Embiggens Salesforce.com
 
Dev ops.enterprise.2014 (1)
Dev ops.enterprise.2014 (1)Dev ops.enterprise.2014 (1)
Dev ops.enterprise.2014 (1)
 
Salesforce Lightning Process builder
Salesforce Lightning Process builderSalesforce Lightning Process builder
Salesforce Lightning Process builder
 
Managing Change With A Sensible Sandbox Architecture
Managing Change With A Sensible Sandbox ArchitectureManaging Change With A Sensible Sandbox Architecture
Managing Change With A Sensible Sandbox Architecture
 
Testing Web Apps and APIs (1)
Testing Web Apps and APIs (1)Testing Web Apps and APIs (1)
Testing Web Apps and APIs (1)
 
Continuous test automation
Continuous test automationContinuous test automation
Continuous test automation
 
Salesforce.com Sandbox management
Salesforce.com Sandbox management Salesforce.com Sandbox management
Salesforce.com Sandbox management
 
Salesforce1 ELEVATE Workshop - Dublin
Salesforce1 ELEVATE Workshop - DublinSalesforce1 ELEVATE Workshop - Dublin
Salesforce1 ELEVATE Workshop - Dublin
 
TDX19 - Accelerate DevOps with GitLab and Salesforce
TDX19 - Accelerate DevOps with GitLab and SalesforceTDX19 - Accelerate DevOps with GitLab and Salesforce
TDX19 - Accelerate DevOps with GitLab and Salesforce
 
Manage Development in Your Org with Salesforce Governance Framework
Manage Development in Your Org with Salesforce Governance FrameworkManage Development in Your Org with Salesforce Governance Framework
Manage Development in Your Org with Salesforce Governance Framework
 
FSL Implementation Guidance Part 1
FSL Implementation Guidance Part 1FSL Implementation Guidance Part 1
FSL Implementation Guidance Part 1
 
Discover salesforce, dev ops and Copado CI/CD automations
Discover salesforce, dev ops and Copado CI/CD automationsDiscover salesforce, dev ops and Copado CI/CD automations
Discover salesforce, dev ops and Copado CI/CD automations
 
Salesforce Release Management - Best Practices and Tools for Deployment
Salesforce Release Management - Best Practices and Tools for DeploymentSalesforce Release Management - Best Practices and Tools for Deployment
Salesforce Release Management - Best Practices and Tools for Deployment
 
WHAT ABOUT QA
WHAT ABOUT QAWHAT ABOUT QA
WHAT ABOUT QA
 

Viewers also liked

Rails Admin - Guru SP
Rails Admin - Guru SPRails Admin - Guru SP
Rails Admin - Guru SPFabio Akita
 
RailsAdmin - the right way of doing data administration with Rails 3
RailsAdmin - the right way of doing data administration with Rails 3RailsAdmin - the right way of doing data administration with Rails 3
RailsAdmin - the right way of doing data administration with Rails 3Bogdan Gaza
 
10 Techniques for Gathering Requirements
10 Techniques for Gathering Requirements10 Techniques for Gathering Requirements
10 Techniques for Gathering Requirementsz-999
 
Automating Deployment Between Orgs Using Git & Continuous Integration
Automating Deployment Between Orgs Using Git & Continuous IntegrationAutomating Deployment Between Orgs Using Git & Continuous Integration
Automating Deployment Between Orgs Using Git & Continuous IntegrationSebastian Wagner
 
Visualforce in Salesforce1: Optimizing your User Interface for Mobile
Visualforce in Salesforce1: Optimizing your User Interface for MobileVisualforce in Salesforce1: Optimizing your User Interface for Mobile
Visualforce in Salesforce1: Optimizing your User Interface for MobileSalesforce Developers
 
RailsAdmin - Overview and Best practices
RailsAdmin - Overview and Best practicesRailsAdmin - Overview and Best practices
RailsAdmin - Overview and Best practicesBenoit Bénézech
 
Structured Approach to Solution Architecture
Structured Approach to Solution ArchitectureStructured Approach to Solution Architecture
Structured Approach to Solution ArchitectureAlan McSweeney
 

Viewers also liked (8)

Rails Admin - Guru SP
Rails Admin - Guru SPRails Admin - Guru SP
Rails Admin - Guru SP
 
RailsAdmin - the right way of doing data administration with Rails 3
RailsAdmin - the right way of doing data administration with Rails 3RailsAdmin - the right way of doing data administration with Rails 3
RailsAdmin - the right way of doing data administration with Rails 3
 
10 Techniques for Gathering Requirements
10 Techniques for Gathering Requirements10 Techniques for Gathering Requirements
10 Techniques for Gathering Requirements
 
Automating Deployment Between Orgs Using Git & Continuous Integration
Automating Deployment Between Orgs Using Git & Continuous IntegrationAutomating Deployment Between Orgs Using Git & Continuous Integration
Automating Deployment Between Orgs Using Git & Continuous Integration
 
Visualforce in Salesforce1: Optimizing your User Interface for Mobile
Visualforce in Salesforce1: Optimizing your User Interface for MobileVisualforce in Salesforce1: Optimizing your User Interface for Mobile
Visualforce in Salesforce1: Optimizing your User Interface for Mobile
 
RailsAdmin - Overview and Best practices
RailsAdmin - Overview and Best practicesRailsAdmin - Overview and Best practices
RailsAdmin - Overview and Best practices
 
Using Visualforce in Salesforce1
Using Visualforce in Salesforce1Using Visualforce in Salesforce1
Using Visualforce in Salesforce1
 
Structured Approach to Solution Architecture
Structured Approach to Solution ArchitectureStructured Approach to Solution Architecture
Structured Approach to Solution Architecture
 

Similar to SF1 - Apex Development Best Practises

Software Quality and Test Strategies for Ruby and Rails Applications
Software Quality and Test Strategies for Ruby and Rails ApplicationsSoftware Quality and Test Strategies for Ruby and Rails Applications
Software Quality and Test Strategies for Ruby and Rails ApplicationsBhavin Javia
 
Automation testing
Automation testingAutomation testing
Automation testingTomy Rhymond
 
Python - code quality and production monitoring
Python - code quality and production monitoringPython - code quality and production monitoring
Python - code quality and production monitoringDavid Melamed
 
Hands-on Experience Model based testing with spec explorer
Hands-on Experience Model based testing with spec explorer Hands-on Experience Model based testing with spec explorer
Hands-on Experience Model based testing with spec explorer Rachid Kherrazi
 
#DOAW16 - DevOps@work Roma 2016 - Testing your databases
#DOAW16 - DevOps@work Roma 2016 - Testing your databases#DOAW16 - DevOps@work Roma 2016 - Testing your databases
#DOAW16 - DevOps@work Roma 2016 - Testing your databasesAlessandro Alpi
 
Unit Testing Full@
Unit Testing Full@Unit Testing Full@
Unit Testing Full@Alex Borsuk
 
XML2Selenium Technical Presentation
XML2Selenium Technical PresentationXML2Selenium Technical Presentation
XML2Selenium Technical Presentationjazzteam
 
Best practices in enterprise applications
Best practices in enterprise applicationsBest practices in enterprise applications
Best practices in enterprise applicationsChandra Sekhar Saripaka
 
Rachid kherrazi-testing-asd-interface-compliance-with-asd spec
Rachid kherrazi-testing-asd-interface-compliance-with-asd specRachid kherrazi-testing-asd-interface-compliance-with-asd spec
Rachid kherrazi-testing-asd-interface-compliance-with-asd specRachid Kherrazi
 
Model Driven Testing: requirements, models & test
Model Driven Testing: requirements, models & test Model Driven Testing: requirements, models & test
Model Driven Testing: requirements, models & test Gregory Solovey
 
Parallel run selenium tests in a good way
Parallel run selenium tests in a good  wayParallel run selenium tests in a good  way
Parallel run selenium tests in a good wayCOMAQA.BY
 
Best practice adoption (and lack there of)
Best practice adoption (and lack there of)Best practice adoption (and lack there of)
Best practice adoption (and lack there of)John Pape
 
Software Testing: Application And Script Independent Automation Framework: Th...
Software Testing: Application And Script Independent Automation Framework: Th...Software Testing: Application And Script Independent Automation Framework: Th...
Software Testing: Application And Script Independent Automation Framework: Th...guest0efb5e
 
Automated Software Testing Framework Training by Quontra Solutions
Automated Software Testing Framework Training by Quontra SolutionsAutomated Software Testing Framework Training by Quontra Solutions
Automated Software Testing Framework Training by Quontra SolutionsQuontra Solutions
 
No Devops Without Continuous Testing
No Devops Without Continuous TestingNo Devops Without Continuous Testing
No Devops Without Continuous TestingParasoft
 
Testware Hierarchy for Test Automation
Testware Hierarchy for Test AutomationTestware Hierarchy for Test Automation
Testware Hierarchy for Test AutomationGregory Solovey
 
Automated Acceptance Tests & Tool choice
Automated Acceptance Tests & Tool choiceAutomated Acceptance Tests & Tool choice
Automated Acceptance Tests & Tool choicetoddbr
 

Similar to SF1 - Apex Development Best Practises (20)

Software Quality and Test Strategies for Ruby and Rails Applications
Software Quality and Test Strategies for Ruby and Rails ApplicationsSoftware Quality and Test Strategies for Ruby and Rails Applications
Software Quality and Test Strategies for Ruby and Rails Applications
 
Automation testing
Automation testingAutomation testing
Automation testing
 
Python - code quality and production monitoring
Python - code quality and production monitoringPython - code quality and production monitoring
Python - code quality and production monitoring
 
Hands-on Experience Model based testing with spec explorer
Hands-on Experience Model based testing with spec explorer Hands-on Experience Model based testing with spec explorer
Hands-on Experience Model based testing with spec explorer
 
#DOAW16 - DevOps@work Roma 2016 - Testing your databases
#DOAW16 - DevOps@work Roma 2016 - Testing your databases#DOAW16 - DevOps@work Roma 2016 - Testing your databases
#DOAW16 - DevOps@work Roma 2016 - Testing your databases
 
Unit Testing Full@
Unit Testing Full@Unit Testing Full@
Unit Testing Full@
 
XML2Selenium Technical Presentation
XML2Selenium Technical PresentationXML2Selenium Technical Presentation
XML2Selenium Technical Presentation
 
Best practices in enterprise applications
Best practices in enterprise applicationsBest practices in enterprise applications
Best practices in enterprise applications
 
Agile testing
Agile testingAgile testing
Agile testing
 
Rachid kherrazi-testing-asd-interface-compliance-with-asd spec
Rachid kherrazi-testing-asd-interface-compliance-with-asd specRachid kherrazi-testing-asd-interface-compliance-with-asd spec
Rachid kherrazi-testing-asd-interface-compliance-with-asd spec
 
Model Driven Testing: requirements, models & test
Model Driven Testing: requirements, models & test Model Driven Testing: requirements, models & test
Model Driven Testing: requirements, models & test
 
Parallel run selenium tests in a good way
Parallel run selenium tests in a good  wayParallel run selenium tests in a good  way
Parallel run selenium tests in a good way
 
Best practice adoption (and lack there of)
Best practice adoption (and lack there of)Best practice adoption (and lack there of)
Best practice adoption (and lack there of)
 
Testing 101
Testing 101Testing 101
Testing 101
 
Software Testing: Application And Script Independent Automation Framework: Th...
Software Testing: Application And Script Independent Automation Framework: Th...Software Testing: Application And Script Independent Automation Framework: Th...
Software Testing: Application And Script Independent Automation Framework: Th...
 
Automated Software Testing Framework Training by Quontra Solutions
Automated Software Testing Framework Training by Quontra SolutionsAutomated Software Testing Framework Training by Quontra Solutions
Automated Software Testing Framework Training by Quontra Solutions
 
No Devops Without Continuous Testing
No Devops Without Continuous TestingNo Devops Without Continuous Testing
No Devops Without Continuous Testing
 
Testware Hierarchy for Test Automation
Testware Hierarchy for Test AutomationTestware Hierarchy for Test Automation
Testware Hierarchy for Test Automation
 
Automated Acceptance Tests & Tool choice
Automated Acceptance Tests & Tool choiceAutomated Acceptance Tests & Tool choice
Automated Acceptance Tests & Tool choice
 
Test Automation Pyramid
Test Automation PyramidTest Automation Pyramid
Test Automation Pyramid
 

Recently uploaded

Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Developmentvyaparkranti
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfkalichargn70th171
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 

Recently uploaded (20)

Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Development
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 

SF1 - Apex Development Best Practises

  • 1. Apex Development Best Practices http://bit.ly/sf1-dev-bp Sebastian Wagner, @tquiladotcom, Technical Architect @seb__wagner
  • 2. “I cannot teach anybody anything, I can only make them think” Socrates
  • 3. Agenda  Principles  Process  Development – Conventions – Queries – Loops – Tests  QA
  • 4. Process  track requirements  separate development sandboxes  use source control (git, Mercury, SVN)  automate deployment with CI  iterate
  • 5. Requirements  Understand – What is expected? – Why, what are the drivers?  Think – How to implement? – Impact, Dependencies  Challenge – Can it be flexed, to match platform features?
  • 6. Platform Advantages  Config over Code – workflows instead of triggers – Page Layout vs. Visualforce  Native over Custom – standard instead of custom objects – re-label field  Install/Deploy over Build – AppExchange – Github
  • 7. XP Principles  MVP - Minimum Viable Product (80/20 rule) – focus on the core features  KISS - Keep It Simple & Stupid – the simplest solution to meet the requirement – easy to use, read and change. looks simple  DRY – Don’t Repeat Yourself – Components, Labels, Templates, Abstraction, Service Classes  YAGNI – You Arent Gonna Need It – implement only WHEN you actually need it
  • 8. DEV – Structure The structure of code and config is clear and understandable  be consistent  use a naming convention  self describing names  declare constants and literal values in variable or config
  • 9. DEV – Comments Loops and more complex parts of the algorithms are clear and commented  clear code (what) over comments (why)  provide context and help understanding  describe purpose of classes and methods  do NOT comment trivial code
  • 10. DEV – Error Handling Exceptions and errors are managed using exception handling  catch in user facing code (e.g. in trigger or controller)  provide useful description if necessary  descriptive error messages  do NOT catch exceptions in service methods, unless you return your own error object
  • 11. DEV – Error Handling  insert Account Deactivation Handler  https://gist.github.com/sebwagner/5e556d492fa2cc010d c9
  • 12. Query - Conditions All SOQL queries are appropriately restricted by a WHERE clause or a LIMIT parameter  filter records by SOQL rather than code  use of indexes (Id, Text, Number) whenever possible  follows best practices for Query Optimizer (e.g. avoid to filter on NULL)
  • 14. Query – Efficiency Efficient use of queries for good performance  cache records for re-use in context  avoid querying the same object multiple times  exclude fields that are not needed  lazy load Blob and Large Text fields
  • 16. Loops - Limits Beware of the Governor Limits  loops (for, do-while) do NOT invoke – SOSL/SOQL statements – DML statements  method calls which use limits are not invoked in loops where avoidable e.g. Describes, Callouts, sendEmail()
  • 18. Testing – Code Coverage Code coverage is no lower than 90%. yet it is not everything, but  high coverage => less bugs => less frustration  keep testability in mind when writing code, because  if you can’t test it, it's an indicator for Code Smell
  • 19. Testing – Code Coverage ‘Alternative’
  • 20. Testing – Test Data Tests setup their own test data @isTest(seeAllData=false)  do NOT rely on organization data  if org data is need, limit to methods  use test data classes or methods for re-use
  • 23. Testing - Assertions Assertions are used to validate expected results  true testing, validation rather than only execution  +1 assert per test method  use the message parameter to provide context system.assert(Object,Object,message);
  • 25. Testing - Scenarios Tests validate positive and negative outcomes  Positive: execution with valid data / params  Negative: execution with invalid data / params  use system.runAs() to test – Dynamic Apex – Methods using with sharing or without sharing – Shared records
  • 27. Testing – Bulk Tests Code should be bulkified, so should be the tests  ensures you don’t hit governor limits  can uncover performance bottlenecks
  • 29. Thank you http://bit.ly/sf1-dev-bp Sebastian Wagner, @tquiladotcom, Technical Architect @seb__wagner

Editor's Notes

  1. 1
  2. 1