14 NOV
2024
Baking a Salesforce
Best Practices Cake
Developer User Group
14 NOV
2024
Peter Caitens
/in/petercaitens
peter.caitens@trailblazercgl.com
Salesforce Lead Developer
8Squad Pty Ltd
Brisbane Developer Group Leader
Ingredients
ā— Good Naming Standards
ā— Descriptive Descriptions
ā— No SOQL/DML in Loops
ā— Bulkify Your Code
ā— One Trigger per Object
ā— No Hard-coded ID’s
ā— Exception Handling and Logging
Instructions
Step 1. Prepare your environment.
Step 2. Mix your ingredients together.
Step 3. Cook.
Step 4. Serve.
Ingredient: Good Naming Standards
What Are They
ā— A document that defines how to name your coding artefacts
ā— Should cover:
ā—‹ Naming Conventions
ā–  Class names
ā–  Variable names
ā—‹ Code Layout & Formatting
ā–  Tabs vs Spaces
ā–  Line Wrapping
ā–  Use of braces
Why
ā— Code maintainability
ā— Developer productivity
Ingredient: Descriptive Descriptions
What Are They
ā— Wherever the Salesforce UI has a Description field you should fill it out
ā— Describe how the field is to be used or example data
Why
ā— Maintainability
ā— Build better Agents
Ingredient: No SOQL/DML in Loops
What Is It
ā— Using DML statements like UPDATE, INSERT, DELETE inside a loop
ā— Using SELECT statement to select records inside a loop
Why Not
ā— SOQL & DML are VERY expensive operations
ā— Avoid governor limits
ā— Makes your code more maintainable
Ingredient: No SOQL/DML in Loops
Ingredient: No SOQL/DML in Loops
Ingredient: Bulkify Your Code
What Is It
ā— Make your code process bulk records at a time
ā— Efficient use of resources
ā— Ensuring all records are processed
Why Not
ā— Avoid governor limits
ā— Makes your code more maintainable
BONUS TIP
Use SOQL SELECT statement in your loops to minimize the heaps size and avoid
governor limits. It also causes the results to be chunked for more efficient
processing.
Ingredient: No Hard-coded ID’s
What Are They
ā— Using Salesforce ID’s in your code
ā— Mostly relates to RecordTypes or default Contacts, Accounts, etc
Why Not
ā— Maintainability
ā— Code Portability
Ingredient: One Trigger per Object
What If I Do
ā— Guarantee the order the code will run
ā— Better code maintainability
ā— Makes testing and debugging easier
What If I Don’t
ā— Causes non-deterministic order of execution
ā— Harder to track errors
What Can I Use
ā— Apex Trigger Actions Framework - Mitch Spano
ā— Nebula Core - Nebula Triggers
ā— ffLib - Financial Force
ā— SFDC Trigger Framework - Kevin O’Hara
BONUS TIP
Counter this with Flows where it is recommended that you have each Flow
encapsulate the logic on the triggered object. Flow Trigger Explorer is your friend
to define the order for each Flow to run.
Ingredient: Exception Handling and Logging
What Is It
ā— Use try/catch statements at your code entry
ā— Present meaningful messages to users
ā— Log errors for future reference
What If I Don’t
ā— Nasty message shown to users
ā— Harder to track problems
What Can I Use
ā— try/catch statements
ā— Nebula Logger
Cooking Instructions
Step 1. Prepare your environment
Step 2. Take all of your ingredients and mix them all together.
Step 3. Cook.
Step 4. Serve
Process: Bake in CICD Pipeline
What Is It
ā— Continuous Integration / Continuous Deployment
ā— Mechanism to ensure changes are tested and verified before Production
ā— Ties together multiple sandboxes for automated code promotion
What To Use
ā— DIY
ā—‹ Salesforce CLI
ā—‹ Github - Actions
ā—‹ Bitbucket
ā—‹ GitLab
ā— Third Party Tools
ā—‹ Gearset
ā—‹ Copado
ā—‹ Flosum
ā—‹ Salto
ā— Salesforce DevOps package
Process: Test Test Test
How
ā— Write good test cases
ā—‹ Positive tests
ā—‹ Negative tests
ā— Automated UI tests
ā— Integration tests
ā— User acceptance tests
Ingredients
ā— Good naming standards
ā— Descriptive Descriptions
ā— No SOQL/DML in Loops
ā— Bulkify your code
ā— One trigger per object
ā— No hard-coded ID’s
ā— Exception Handling and Logging
Process
ā— Bake in a CI/CD pipeline
ā— Test, test, test
14 NOV
2024
THANK YOU

Down Under Dreaming Brisbane 2024 - Developer Session - Baking a Salesforce Best Practices Cake

  • 1.
    14 NOV 2024 Baking aSalesforce Best Practices Cake Developer User Group
  • 2.
    14 NOV 2024 Peter Caitens /in/petercaitens peter.caitens@trailblazercgl.com SalesforceLead Developer 8Squad Pty Ltd Brisbane Developer Group Leader
  • 4.
    Ingredients ā— Good NamingStandards ā— Descriptive Descriptions ā— No SOQL/DML in Loops ā— Bulkify Your Code ā— One Trigger per Object ā— No Hard-coded ID’s ā— Exception Handling and Logging
  • 5.
    Instructions Step 1. Prepareyour environment. Step 2. Mix your ingredients together. Step 3. Cook. Step 4. Serve.
  • 6.
    Ingredient: Good NamingStandards What Are They ā— A document that defines how to name your coding artefacts ā— Should cover: ā—‹ Naming Conventions ā–  Class names ā–  Variable names ā—‹ Code Layout & Formatting ā–  Tabs vs Spaces ā–  Line Wrapping ā–  Use of braces Why ā— Code maintainability ā— Developer productivity
  • 7.
    Ingredient: Descriptive Descriptions WhatAre They ā— Wherever the Salesforce UI has a Description field you should fill it out ā— Describe how the field is to be used or example data Why ā— Maintainability ā— Build better Agents
  • 8.
    Ingredient: No SOQL/DMLin Loops What Is It ā— Using DML statements like UPDATE, INSERT, DELETE inside a loop ā— Using SELECT statement to select records inside a loop Why Not ā— SOQL & DML are VERY expensive operations ā— Avoid governor limits ā— Makes your code more maintainable
  • 9.
  • 10.
  • 11.
    Ingredient: Bulkify YourCode What Is It ā— Make your code process bulk records at a time ā— Efficient use of resources ā— Ensuring all records are processed Why Not ā— Avoid governor limits ā— Makes your code more maintainable BONUS TIP Use SOQL SELECT statement in your loops to minimize the heaps size and avoid governor limits. It also causes the results to be chunked for more efficient processing.
  • 12.
    Ingredient: No Hard-codedID’s What Are They ā— Using Salesforce ID’s in your code ā— Mostly relates to RecordTypes or default Contacts, Accounts, etc Why Not ā— Maintainability ā— Code Portability
  • 13.
    Ingredient: One Triggerper Object What If I Do ā— Guarantee the order the code will run ā— Better code maintainability ā— Makes testing and debugging easier What If I Don’t ā— Causes non-deterministic order of execution ā— Harder to track errors What Can I Use ā— Apex Trigger Actions Framework - Mitch Spano ā— Nebula Core - Nebula Triggers ā— ffLib - Financial Force ā— SFDC Trigger Framework - Kevin O’Hara BONUS TIP Counter this with Flows where it is recommended that you have each Flow encapsulate the logic on the triggered object. Flow Trigger Explorer is your friend to define the order for each Flow to run.
  • 14.
    Ingredient: Exception Handlingand Logging What Is It ā— Use try/catch statements at your code entry ā— Present meaningful messages to users ā— Log errors for future reference What If I Don’t ā— Nasty message shown to users ā— Harder to track problems What Can I Use ā— try/catch statements ā— Nebula Logger
  • 17.
    Cooking Instructions Step 1.Prepare your environment Step 2. Take all of your ingredients and mix them all together. Step 3. Cook. Step 4. Serve
  • 18.
    Process: Bake inCICD Pipeline What Is It ā— Continuous Integration / Continuous Deployment ā— Mechanism to ensure changes are tested and verified before Production ā— Ties together multiple sandboxes for automated code promotion What To Use ā— DIY ā—‹ Salesforce CLI ā—‹ Github - Actions ā—‹ Bitbucket ā—‹ GitLab ā— Third Party Tools ā—‹ Gearset ā—‹ Copado ā—‹ Flosum ā—‹ Salto ā— Salesforce DevOps package
  • 20.
    Process: Test TestTest How ā— Write good test cases ā—‹ Positive tests ā—‹ Negative tests ā— Automated UI tests ā— Integration tests ā— User acceptance tests
  • 21.
    Ingredients ā— Good namingstandards ā— Descriptive Descriptions ā— No SOQL/DML in Loops ā— Bulkify your code ā— One trigger per object ā— No hard-coded ID’s ā— Exception Handling and Logging Process ā— Bake in a CI/CD pipeline ā— Test, test, test
  • 23.