When any team at Salesforce builds a new feature, we remind ourselves that every customer is unique. That is why we build features to be customizable and extendable. Salesforce CLI is no different: We know that as a developer your workflow is unique, and although Salesforce CLI comes with a great set of commands right out of the box, you might need something more. That is why the Salesforce CLI team worked closely with the Heroku team to give you the ability to create your own custom commands.

We call this Plug-In Generation and it is built on top of Heroku’s Open CLI Framework (oclif). When you run the Salesforce CLI command sfdx plugins:generate, the Salesforce CLI plug-in wizard leads you through the configuration steps for your new command and generates a plug-in project. You start with a scaffolded command, basically a fully functional “Hello World” command, and the project’s file structure so you don’t need to start from scratch.

Today, Plug-In Generation is generally available and we are open sourcing the Core and Command Libraries to allow you to dig into the code and if there is a functionality you wish to see, contribute back the repository.

What are we announcing today?

  1. Plug-In Generation is GA: We provide the scaffolding to get you going so you can build whatever you want. Plus, when you generate a new plug-in, there is an example command in the project folder you can dig into.
  2. A plug-in developer guide: The Salesforce CLI Plug-In Developer Guide walks you through the process of building a plug-in with examples so you can get going now.
  3. Open-sourcing the CLI Core and Command libraries:
    1. The Core Library is a NodeJS module that contains all the “core” utilities of the Salesforce CLI infrastructure. These utilities include authentication, config, project management, and much more. Your plug-in can use the Core library to access information in the same way the force:commands do. Explore the Examples folder in the repo, because you can do more than just Plug-In Generation with the Core Library.
    2. The Command Library gives your plug-in access to flag parsing, argument parsing and validation, and help: all the things that a good command should have. Using the Command library allows you to make your command consistent with other SFDX commands and to be user-friendly.

What can I build?

If you already have custom scripts that you use with Salesforce CLI, revisit those scripts to determine if it makes sense to create a custom plug-in instead. Whenever you want to perform repetitive tasks and have to support multiple operating systems or work across multiple DX repositories a custom command or set of commands may make your team’s workflow better.

For example, let’s say you have a custom linting program that you want your team to run every time they push to a scratch org. You can create a plug-in that does just that.

Another example of a command that you can create might be to post to Chatter when you deploy your code to a sandbox or create a new package version. In this case you could create a command that connects to your Salesforce Chatter feed and then add that command to your build or automation scripts. The possibilities are only constrained by your imagination!

How do I get started?

If you are the type that wants to dive right in, run the ‘sfdx plugins:generate’ command and start exploring scaffolded project. If you are the type that wants to do get the lay of the land first, start by reviewing the Salesforce CLI Plug-In Developer Guide. This will help you get a feel for what you need to start building and how to get started. Then, go review the platform event streamer plug-in to see a plug-in in action (you can even watch this Dreamforce talk about how it was made). Review how the plug-in works and how it incorporates the Core and Command libraries.

What’s coming?

We are excited to share this with you now, but we also have more that we plan to build to make Plug-In Generation even more useful. We are currently building a community signing feature so you can sign your plug-ins. After that is available, we plan to create commands in the CLI that allow Salesforce CLI users to search for plug-ins and get suggestions directly from the CLI. That way you can share your plug-in with the Salesforce Developer community.

We are excited to see what you build, so don’t forget to share your creations with us on social media #sfdx.

To learn more about Salesforce CLI, check out the Trailhead Quick Start on Salesforce DX.

About the author

Claire Bianchi is the Product Manager for the Salesforce CLI. She joined Salesforce in June 2018. Prior to this role she was at Atlassian as the Product Manager of the Bitbucket Ecosystem and Front End teams. She holds two degrees from the University of California, Berkeley, a BA in Economics and an MBA from the Haas School of Business. Prior to grad school, she was in database marketing at Hotwire.com and ran CRM at UniversityNow. Follow Claire on Trailhead, LinkedIn, and Twitter.

Get the latest Salesforce Developer blog posts and podcast episodes via Slack or RSS.

Add to Slack Subscribe to RSS