How to improve Salesforce developer productivity and code quality

The build tools I use to make my code less ugly and error prone

Salesforce is aligning with industry standards and tools for development. Here are some things that Salesforce developers have now to help improve their productivity.

  • A command line interface to run common tasks
  • Extending the command line interface with custom plugins
  • Writing standard JavaScript code for component development
  • Improvements for packaging code with semantic versioning
  • Access to community and industry plugins
Three pillars for DX, Formatting and Code Quality showing tool icons
Three pillars for DX, Formatting and Code Quality showing tool icons
My setup for raising the bar in quality and consistency when programming for Salesforce

Taming the Salesforce CLI

Salesforce released the Salesforce CLI as part of a new way of interacting scratch orgs, source code and metadata in your instance of Salesforce. The new command line has 100s of command and options that can be used by developers to help them pull, push and modify code and test data.

Oh My Zsh

Oh My Zsh is an open source, community-driven framework for managing your zsh configuration. It has thousands of active contributors and a huge library of plugins and themes. I love the solarised theme with Menlo fonts but their are literally thousands of colour themes to choose from.

Auto suggestions. It’s like it can read my mind.
Working with the git plugin for zsh is visual

Salesforce CLI Autocomplete

So far we’ve supercharged the command line but haven’t specifically addressed how we can get to grips with the commands unique to the Salesforce CLI. For this we can use the Salesforce CLI Autocomplete plugin.

Formatting Rules

Most programmers I have met are opinionated about how they format their code. In fact, hours of debate can be had when a new development team forms on the best way to achieve formatting consistency. Consistency is important as peer reviews are an important part of the software development lifecycle and reviewing disparately formatted code can be hard, can impact productivity and slow down the review.

Prettier

Prettier is an opinionated code formatter that supports a wide number of programming languages. It takes the development team from debating what should work to something that can be systematically applied.

VS Code plugin for Prettier to format code in the IDE
“scripts”: {
“prettier”: “prettier — write ‘**/*.{cls,cmp,component,css,html,js,json,md,page,trigger,yaml,yml}’”,
“prettier:verify”: “prettier — list-different ‘**/*.{cls,cmp,component,css,html,js,json,md,page,trigger,yaml,yml}’”
},
“devDependencies”: {
“prettier”: “^.0.5”,
“prettier-plugin-apex”: “^.5.0”
},
Before: I tend to format my code without consideration for line length. Arguably making it harder to read.
After: Prettier ensures appropriate line breaks and improves consistency for code reviews.
Before: My SOQL queries typically run over multiple lines with indentation.
After: Prettier simplifies the formatting to ensure consistency.

Code Quality Rules

Code quality can be impacted directly by a developers ability to follow best practices to avoid common programming pitfalls.

PMD

PMD is an extensible cross-language static code analyser where support for Apex has been added by an active community.

VS Code plugin for PMD to execute code analysis in the IDE
Contextual help on line numbers highlights issues immediately. In this case a naming convention violation and corresponding mismatch with the associated comment
PMD summarises all issues found with associated line numbers and category of issue

ESLint

Where PMD finds and fixes issues with your Apex code ESLint does the same for your JavaScript code. For developers transitioning to JavaScript from Salesforce proprietary Visualforce or Aura this can be a productivity boost.

VS Code plugin for ESLint to execute code analysis in the IDE

SLDS Validator

SLDS Validator is a useful utility that scans your markup and validates it against guidelines extracted from the Salesforce Lightning Design System documentation. I have found this particularly useful since class names change over time and I have found instances where my HTML markup was still referencing the old classnames.

VS Code plugin for SLDS Validator to execute analysis in the IDE
Inline suggestions help fix SLDS issues quickly
SLDS Validator can help identify deprecated classes and suggest the new name to use

Summary

Team based environments call for consistency and a projects success is dependent on quality. How you choose to setup your development environment can have a direct impact on these outcomes.

Further Reading

Developer Advocate @ MuleSoft || Interested in solving unique challenges using different cloud service providers || All opinions are mine.