Create A Salesforce DX Plugin In just 15 Minutes.

Have you ever considered how beneficial it would be to generate a configuration workbook or compare sandboxes for differences before deploying metadata in a Sandbox or production environment? What about checking if fields are utilized on any page layouts? If these thoughts resonate with you, then you may find a custom Salesforce DX plugin to be invaluable.

The initial step involves installing yarn using the following command.

sudo npm install -g yarn

After that, execute the command below to generate a plugin template for Salesforce DX. This template comes pre-loaded with all the necessary boilerplate code to establish a connection to Salesforce and perform data queries.

sfdx plugins:generate


After creating the plugin, the next step is to associate it with Salesforce DX using the following command.

sfdx plugins:link foldername
#If already in folder then folder name would be blank
sfdx plugins:link

Here is the directory structure.

Salesforce DX Plugin Structure

Based on the folder structure mentioned above, if I’m executing a command from the DF18DEMO directory and the “src” folder is the immediate folder containing the plugin code, then the following command would be used to associate this code with Salesforce DX.

sfdx plugins:link

To run this plugin, we need to run command

sfdx hello:org -u jit11

Above, jit11 is already approved org using command sfdx force:auth:web:login

Below image shows summary of commands and its results

Salesforce DX Commands

USAGE
  $ sfdx DF18:fileoutput
 
OPTIONS
  -f, --force                                      example boolean flag
 
  -m,                                              Comma separated list of objects to be exported
                                                   If blank then every object of Org would be exporte
 
  -p, --path                                       File Name with full Path to
                                                   create Excel File
 
-u, --targetusername=targetusername              username or alias for the
                                                   target org; overrides default
                                                   target org

  -v, --targetdevhubusername=targetdevhubusername  username or alias for the dev
                                                   hub org; overrides default
                                                   dev hub org
 
  --apiversion=apiversion                          override the api version use
                                                   for api requests made by this
                                                   command

  --json                                           format output as json
 
  --loglevel=(trace|debug|info|warn|error|fatal)   logging level for this
                                                   command invocation
 
EXAMPLE
  Example : sfdx DF18:fileoutput -u jit27 -m "Account,Lead,Opportunity"
Jitendras-MBP:sfdx-plugin jitendra.zaaibm.com$ sfdx DF18:fileoutput --help
USAGE
  $ sfdx DF18:fileoutput

OPTIONS
  -f, --force                                      example bool

  -m,                                              Comma separated list of objects to be exported.
                                                   If blank then every object of Org would be exporte
 
  -p, --path                                       File Name with full Path to
                                                   create Excel File