Salesforce is a powerful and versatile platform, but like any technology, it’s important to follow best practices to ensure success. Join us to learn about Salesforce Implementation tips & tricks and best practices in the Software development life cycle. Here are some Salesforce best practices to keep in mind.
What is Salesforce’s Best Practices?
Salesforce best practices are guidelines that help ensure the success and optimal use of the Salesforce platform. They cover various aspects of Salesforce, including data management, customization, security, governance, training, and testing. Here are some key Salesforce best practices to keep in mind
- Keep data clean: All best practices start with data. Make sure your data is accurate, complete, and up-to-date. This will help you make informed decisions and avoid errors. So focused to data modeling in Salesforce.
- Avoid over-customization: Use our out-of-the-box customization if it’s necessary to meet your business requirements. Avoid over-customization and code, as it can lead to technical debt and future maintenance headaches.
- Platform Security: Configure your security settings to control access to data and features. Use strong passwords and two-factor authentication to protect against unauthorized access.
- Project Governance: Setup Governance model required in Salesforce projects. Establish governance policies to ensure that users follow best practices, such as data entry standards, naming conventions, and report creation guidelines.
- User Training: Train users to ensure they have the skills and knowledge to use Salesforce effectively. This will help them get the most out of the platform and reduce support requests.
- Testing: Test your changes in a sandbox environment before deploying to production. This will help you avoid unintended consequences and ensure your changes work as expected. Check our Salesforce testing guide.
Learn more about Salesforce Implementation Tips & Tricks.
Salesforce best practices for developers
What about Salesforce Platform Best Practices? Here are some best practices that we documented for Developers.
1. Salesforce Apex Code Best Practices
As with any language, there are key coding principles and best practices that will help you write efficient, scalable code. Regarding Salesforce Apex’s best practices, there are a few key things to remember.
- Bulkify Apex Code
- Avoid SOQL & DML Inside For Loop
- Optimize SOQL Queries to avoid Timeout Issues
- Use Of Map Of Sobject
- Use Of The Limits Apex Methods
- Avoid Hardcoding IDs
- Use Database Methods While Doing DML Operation
- Exception Handling In Apex Code
- Write One Trigger Per Object Per Event
- Use Asynchronous Apex
- Security And Sharing In Apex Code
- Make Reusability Of Apex Code
- Code Coverage
- Return Early Pattern
- Avoid Nesting Loops Within Loops
- Don’t Mix Apex, Process Builders, Workflow Rules, And Record-Triggered Flows
- Apex Naming Conventions
- Setup Code Review Checklist And Code Review Process
- Apex Performance
Learn all Salesforce Apex Code Best Practices with example.
2. Salesforce Flow Best Practices
By following below best practices, you can create effective and efficient flows that automate your business processes and improve productivity.
- Always! Plan Before You Build
- No DML Statement In Loops
- Use The Advanced Technique To Merge Decision Node
- Build Reusable Flow(S) – Subflow(S)
- Don’t Create Flow For Everything
- Build In A Test/Sandbox Environment
- Supercharge Flow With Invocable Apex
- Don’t Hardcode IDs; Query For Them
- Don’t Mix Trigger, Process Builder, Flow, And Record Trigger Flow
- Handle Errors With Fault Paths
- Exception Handling In Flow Using Platform Events
- Use Debug Log To Check Why A Flow Fails At Runtime
- Document Your Flows
- Flow Naming Conventions
- Screen Flow UI Design Tips
- Tests For Salesforce Flow
Learn Salesforce Flow Best Practices with examples.
3. SOQL Best Practices
When dealing with Large Data, your SOQL query may return so many Objects that the limit on heap size is exceeded, and an error occurs. Here are Apex SOQL’s best practices in Salesforce and how important it is when you’re dealing with large databases.
- Building Efficient & Selective Queries
- Common Causes Of Non-Selective SOQL Queries
- Query Optimizer
- Avoiding Querying On Formula Fields
- Custom Indexes Containing Null Rows
- Delete Record From Recycle Bin
- LastModifiedDate Vs SystemModStamp
- SOQL Injection
- SOQL Vs SOSL
- Avoid SOQL Inside FOR Loops
Learn SOQL Best Practices with example.
4. Apex Test Class Best Practices
Unit tests are the tests performed by the developers to ensure that functionality is working as expected, considering Both positive and negative tests. We should not focus on the percentage of code coverage we should focus on the below test class best practices.
- Focus on 90+ code coverage.
- One Assert Statement per method.
- Use @testSetup to create test records once.
- Create TestFactory class
- No SeeAllData=true.
- Use System.runAs to enforce record sharing.
- Avoid Using Hard Coding Ids.
- Using
Test.startTest()
gives developers a new set of governor limits for the act stage of their test.Test.stopTest()
then allows them to return to their previous governor limits. - Exercise bulk trigger functionality
Check Apex Test Class Best Practices with examples.
5. Lightning Web Components (LWC) Best Practice
Learn Lightning Web Components (LWC) Best Practices like when to use apex class and when not to use apex class. When should we use which event in LWC. Here are Lightning Web Components (LWC) Best Practice.
- LWC Component Bundle Naming Convention
- Calling Apex From LWC- Wire Vs Imperatively
- Event In LWC- When to use which event
- Streaming API, Platform Event, Change Data Capture
- How To Debug LWC
- Use Storable Action/ Cache Data
- Build Reusable Lightning Web Components
- Styling Reusable Components
- LWC Best Practices Guide.
- Lazy Loading In LWC
6. OmniStudio Best Practices
Salesforce Industries (Vlocity) Digital Platform Components are divided in the following categories. FlexCard, OmniScript, DataRaptor, and Integration Procedures. Here are OmniStudio Best Practices which can help you to learn omnistudio.
Learn more about platform best practices.
Summary
By following these best practices, you can help ensure your Salesforce implementation is successful and delivers value to your organization.