How many times do you need to google your favorite Salesforce DX Commands? Or you used some commands in your last project to automate deployment and were not able to recall them & access them quickly when you need to?
I have been using Task.json for a long time in VSCode for
- Keep my favorite commands at my fingertips
- Automate a series of commonly used commands.
- Reuse automated deployment scripts.
Common Task.json I have been using in all of my projects and keep updating them with any new command.
In this blog post, I would share a snippet of my Task.json and ten reasons to use them.
1. Streamlined Development Workflow
Task.json allows you to define and automate common development tasks, such as deploying metadata, running tests, generating code coverage reports, creating scratch orgs, and more. This streamlines your development workflow and saves time.
2. Consistent Development Environment
With Task.json, you can define tasks that set up consistent development environments across your team. You can specify the Salesforce CLI commands, options, and parameters required for specific development tasks, ensuring consistency and reducing configuration discrepancies.
3. Scratch Org Creation and Management
Task.json enables you to define tasks for creating and managing scratch orgs. You can specify the Salesforce CLI commands to create, delete, or update scratch orgs, allowing for easy provisioning and managing isolated development environments. In most of my projects, after scratch org creation, I have a series of managed packages that need to be deployed, and it all happens with a single command.
4. Automated Metadata Deployment
Using Task.json, you can automate the deployment of metadata to Salesforce orgs. You can define tasks to deploy specific metadata components or entire packages, ensuring smooth and consistent deployments without manual intervention.
5. Test Execution and Code Coverage
Task.json allows you to define tasks for executing tests and generating code coverage reports. You can set up tasks to run unit tests, integration tests, or specific test suites, providing automated feedback on the quality and coverage of your Salesforce code.
6. Source Code Validation
Task.json enables you to define tasks for validating your source code against Salesforce best practices and coding standards. You can incorporate static analysis tools like PMD, ESLint, or TSLint into tasks, ensuring code quality and adherence to standards.
7. Apex Documentation
Task.json can be used to bundle multiple commands in single commands, as mentioned in points 4,5,6, along with Java-like document generation using ApexDox VS Code extension.
8. Continuous Integration and Deployment (CI/CD) Integration
Task.json is essential for integrating Salesforce development with CI/CD pipelines. You can define tasks that execute Salesforce CLI commands to deploy code to different environments, allowing for automated deployments and continuous integration. Note – It would work only from systems where VSCode has been installed. However, the same scripts can be used in tools like Jenkins, Git pipeline, or Azure DevOps because, at last, these are shell scripts. Task.json can be used to define tasks that facilitate Git operations within your Salesforce projects. You can define tasks for committing changes, pushing to remote repositories, pulling changes, and resolving merge conflicts, ensuring smooth Git integration within your development workflow.
9. Developer Productivity
By automating repetitive tasks and providing a standardized workflow, Task.json enhances developer productivity. It eliminates manual steps, reduces errors, and allows developers to focus more on coding and building Salesforce applications.
10. Extension Integration
Task.json integrates well with various extensions in the VSCode ecosystem. Many extensions provide additional functionality by defining and utilizing tasks through Task.json. This allows for the seamless integration of tasks with linters, formatters, test runners, and other development tools.
As you can see below sample, Create Scratch Org & Install Package is the combination of multiple commands.
Another inconvenience to look out for is that if you have a long wait time to execute all commands and one of the last commands needs input; the whole process stops unless someone enters a parameter.
To solve the above issue, I have a command Input For Scratch Org & Package, which print all inputs in echo, and later if any command needs that same parameter, I’m not asked to provide value again.
How to execute
- Click Cmd +Shift + P in VSCode
- Select Tasks: Run Task
- Choose a list of tasks defined in your task.json and follow the prompt