Part II: Key Takeaways
In the last article, we introduced the two different development models of Salesforce and the common problems encountered during its development and deployment process.
This article will give a detailed overview of how to use the DevOps mindset to improve the overall Salesforce development experience.
Key Takeaways of Salesforce DevOps
DevOps is a combination of culture, ways of working, tools and practices, to accelerate the process from product idea to implementation to production release through agile team collaboration and automated tools.
We have adjusted the DevOps practices based on the characteristics of Salesforce development, and summarized the practices as follows, from requirements management, development model, package management to test and security strategies. Implementing the following practices can add value to customers.
1. Plan the business requirements elaborately to decrease the failure rate of deployment
Because of the natural disadvantages of Change Set, there are often big bulk deployments with many changes, and the team has little motivation to plan each story at a level of granularity that is more elaborate and less dependent.
The recommended practice is to be more considerate about the completeness, dependencies and deployment sequences, to better compose the user stories and map them with metadata. Make the changes to each story more transparent and trackable with VCS tools to decrease the omitted components and conflicting functionalities.
2. Adopt a suitable development model to better manage code and improve deployment efficiencies.
Although the Org-based model is still widely used for now, more and more developers will move forward with the Package-Based model. Under the Package-Based model, the developer will have no need to manage a large number of metadata files, instead they can use a more granular way to manage files in the source format. In addition, the Package-Based model is more compatible with Salesforce CLI, which will help the deployment much more reliably and frequently.
3. Introduce source code version control system for better team collaboration
Changing the single source of truth from production org to VCS enables the team to more easily review each other’s contributions and track the code changes to avoid members stepping on each other's toes.
4. Use proper branching strategy to enhance team collaboration
Teams need an appropriate branching strategy to best match the business requirements, maximize productivity and manage team delivery cadence. Let’s take the feature branch model as an example.
The Scratch Org is introduced to avoid development conflict, and the shared beta package could be reused in different environments which improves deployment efficiency.
Figure 1: Salesforce feature branch model
5. Automate deployment via CI/CD tools
CI/CD is a sure-fire tool to make deployments more reliably and frequently. Teams can either choose commercial tools or open-source/free tools based on the skill sets, agile maturity and budget of your team.
Commercial tools
The commercial tools offer a convenient user interface and a relatively complete set of functional modules such as VCS, CI/CD, code scanning, testing, etc. Users can tailor the deployment steps to fit their team with only some simple configurations.
However, there are many limitations to using this kind of commercial software, such as the relatively low level of customizability of processes and functionality for teams.
Open-Source/Free Salesforce tools
Another way is to select free Salesforce first-party tools. We found that Salesforce is focusing more and more on the development experience, and improving a lot on the tools they provide. For example, after the release of SFDX, Native Backup & Restore product, Salesforce will officially launch the DevOps Center this year, which is a more powerful tool to assist admins and developers with collaboration and deployment.
Before the DevOps Center is widely used, the SFDX is still the popular tool to set up individual CI/CD. You can easily implement the CI/CD on common tools like CircleCI, Jenkins, GoCD,etc. through the functions of SFDX.
6. Test strategies to balance test efficiency and project quality
Referring to the test pyramid approach, we recommend the following practices:
Follow the TDD practice and ensure high Apex unit test coverage
Reduce interaction with Salesforce DB by introducing the mocking and stubbing frameworks
Improve system stability and business success by automated integration testing
Integrate automated UI testing into the CI/CD to reduce repetitive and cumbersome manual smoke and regression testing. (like Cypress.io, Cucumber frameworks etc.)
Figure 2: Test pyramid
And in reducing the test running time during the CI process, we also have some practical experiences.
When running unit tests, we usually choose to run only specific test classes to reduce the time spent during the CI process. However, if we do need to run all test classes to verify the overall quality, we can choose to synchronously run them in multiple parallel sandboxes.
Network requests are time consuming in UI automation testing. A good practice is to prioritize the UI test cases, schedule the high priority test cases and full test cases at different times as needed.
7. Introduce professional tools for the project’s security and quality
To systematically track and improve Code Quality and Code Security, you could involve some tools. For example, Whispers can be used to inspect the credentials info, Prettier can help unify the code format and configuration, Eslint is for the Javascript clean code, and PMD is used to ensure the APEX code performance and security etc.
Figure 3: Tools and Plugins
Summary
By introducing the idea of DevOps, we can start improving the Salesforce development experience from all aspects. Accordingly, we’ve summarized some good key DevOps practices during the implementation process. But this is not a ‘Silver Bullet’, if you want to improve the entire team’s quality and efficiency, the key is to build up a DevOps culture, encourage an agile way of working, team collaborative communication, and break down work silos between teams.
Disclaimer: The statements and opinions expressed in this article are those of the author(s) and do not necessarily reflect the positions of Thoughtworks.