Build a Salesforce DX Plugin in 15 Min

My Dreamforce Session to create a Salesforce DX plugin in 15 minutes

Build a Salesforce DX Plugin in 15 Min

Before deploying metadata in Sandbox of production, have you felt that how great it would be to generate configuration workbook ? Or compare sandboxes for difference ? Or check if fields are used on any page layouts or not ? Dear reader, you are in need of custom Salesforce DX plugin.

You heard it right, Salesforce DX allows custom plugin development. So now question is, how do you connect to Salesforce Org ? Do you need to know about OAuth or Single Sign On (SSO) ?

Complete source code is available on my Github repository here.

Prerequisite

  1. Nodejs Installed
  2. Salesforce DX Installed

First step is to install yarn using below command

sudo npm install -g yarn

Next is to run below command, it will create a plugin Template for Salesforce DX which already has all boilerplate code to connect to Salesforce and query data.

sfdx plugins:generate 

Once plugin created, it’s time to link this plugin with Salesforce DX using below command

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

Below is the structure of directory

Salesforce DX Plugin Structure
Salesforce DX Plugin Structure

As per above folder structure, I’m running command from DF18DEMO and src is immediate folder which contains plugin code, then below command would be used to link 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
Salesforce DX Commands

Download code from here , To run plugin which generates workbook. After downloading, run link command. Below are detail of various command parameters

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 exported

  -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 used
                                                   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 boolean flag

  -m,                                              Comma separated list of objects to be exported. 
                                                   If blank then every object of Org would be exported

  -p, --path                                       File Name with full Path to
                                                   create Excel File

Related posts

One thought on “Build a Salesforce DX Plugin in 15 Min”

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.