Best Practices with Salesforce Apex in 2022

#1MinuteTip Time to review / update your Apex best practices in Salesforce. Here is exactly what you need. In TrailblazerDX 2022 (#TDX22), Mohit Shrivastava & Kevin Poorman from Salesforce did a presentation on the same and have very kindly shared the presentation with everyone.

Recommended Framework for Salesforce Triggers

#1MinuteTip A good framework gives you a structure based on best practices that you can reuse. It is optimized, increases the speed of development & improves the efficiency of your code. Implementing a good framework becomes more important when you are working on a multi-tenant platform like Salesforce where there are limits on the amount of resources you can use. 

Salesforce recommends one such framework to implement your triggers. As mentioned in the Trailhead Module Success Cloud Coding Conventions -> Implement Framework, it says “Having said that, Kevin O’Hara’s SFDC Trigger Framework is the one we generally prefer on large-scale projects within the Success Cloud team at Salesforce.

Check it out at URL https://github.com/kevinohara80/sfdc-trigger-framework

Recommended Framework for Salesforce Triggers based on best practices

#SalesforceSummer21 – Run Apex Code in User Mode (Pilot)

#1MinuteTip #SalesforceSummer21 By default Apex code executes in system mode and doesn’t respect running user permissions. To enhance the security context of Apex, you can specify user-mode access for database operations by invoking Apex in user mode. The field-level security (FLS), sharing rules, and CRUD permissions of the running user are respected in user mode, unlike in system mode.

Available as pilot, you can now declare when Apex runs database operations in user mode or system mode.

References & Useful URLs

How to Delete or Deactivate Apex Class / Trigger in Salesforce Production Org

How do you delete or deactivate the apex classes / triggers on your Salesforce Production Org? Unfortunately, it is not as simple as going to the Apex class and hitting the delete button or unchecking the ‘Active’ checkbox.

For deleting or disabling the code, you can take one of the following two routes:

Check the Quality of Your Code in Salesforce

#1MinuteTip How secure and performant is your code in Salesforce? Is it following the best practices? Can it be improved further? Are there any vulnerabilities? Don’t forget to pass it through the Force.com Code Scanner before deploying any new code. It’s free.

Quality of Code in Salesforce

Or please refer to the page Useful Resources: Source Code Analysis Tools for a list of different static source code analysis tools for Salesforce