Skip to main content
Gruppo

SFDX CLI Plug-in Development

This group is dedicated to conversations and questions about creating custom SFDX CLI plug-ins. A plug-in adds functionality to Salesforce CLI. Some plug-ins are provided by Salesforce and are installed by default when you install the CLI. Some plug-ins, built by Salesforce and others, you install. When you have a requirement that an existing plug-in doesn’t meet, you can build your own using Node.js. For more information on building your own CLI plug-in see the Plug-in Developer Guide: https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_plugins.meta/sfdx_cli_plugins/cli_plugins.htm

With the latest version of the CLI, hooks are not firing anymore for me.

If I downgrade salesforce-alm to 49.11.0 it's working again.

 

Is anyone using them and seeing similar issues ?

 

https://github.com/forcedotcom/cli/issues/578

 

cc @Thomas Dvornik  

1 commento
0/9000

Using the --json switch with an SFDX command returns JSON to stdout. However, if I consume a command in a node process, e.g. 

 

child_process.execFileSync('sfdx', ['force:limits:api:display', '-u', 'alias', '--json']).toString();

 

It does return the JSON, but due to the CLI formatting if the JSON (i.e. the colours) we get all the ANSI escape codes too (so instead of e.g. { } we get \u001b[97m{ \u001b[97m}) making it more effort to parse. Is there a way to get raw JSON back instead of formatted?

5 commenti
  1. 5 ott 2020, 07:03

    Hi, I have this method in my node app to parse sfdx commands json response:

    private asyncSfdxCommand(command: string) {

    return new Promise((resolve, reject) => {

    exec(command, (error, standardOutput, standardError) => {

    if (error) {

    reject();

    return;

    } else if (standardError) {

    reject(standardError);

    return;

    }

    resolve(standardOutput);

    });

    });

    }

    And I use it this way:const myResponse = JSON.parse(await this.asyncSfdxCommand(`sfdx force:limits:api:display -u MyExampleUser --verbose --json`));

    In the variable I get myResponse the json perfectly parsed and I can get access to all the properties.

    Hope it helps.

0/9000

In a custom SFDX CLI plugin, how do I return a nice non-zero status code and error message so that they can be correctly interpreted by shell scripts and also programs reading the --json output ?

2 commenti
0/9000

Hi, does anyone use pre-commit hooks to reorder XML files to minimize diffs down the pipeline ?  Do you have best practices crafted from this experience ?

 

#precommit #XML Reorder 

7 commenti
  1. 29 set 2020, 17:21
    @Rupert Barrow

    Our process is older (still using MDAPI) and a bit weird, but we end up doing a lot of things on a build server -- have jobs that retrieve the metadata from an org, then immediately format it before committing.

    I imagine a git pre-commit hook could work.

    You can also customize the SFDX CLI with command hooks, so perhaps you could implement a "postretrieve" command hook to sort and format the XML files as well. Good post here:

    https://developer.salesforce.com/blogs/2020/09/the-cli-and-salesforce-extensions.html
0/9000

*** Salesforce CLI plugin for Custom Metadata Types is now available ***

 

Hello SFDX enthusiasts.

 

We are happy to announce that the CLI plugin for custom metadata types is available in CLI v49. These new commands simplify development and help you build automation and synchronize your source from scratch orgs when working with custom metadata types.

 

You can use the Salesforce command-line interface to create custom metadata types, fields and records. Additionally, you now will be able to bulk insert records from a CSV file or use an existing custom object / setting to generate custom metadata types from it.

 

Plugin - force:cmdt

Commands -

  • force:cmdt:create. Creates a custom metadata type in the current project.
  • force:cmdt:field:create. Generates a custom metadata field based on the provided field type.
  • force:cmdt:generate. Generates a custom metadata type and all its records for the provided sObject.
  • force:cmdt:record:create. Creates a record for a given custom metadata type in the current project.
  • force:cmdt:record:insert. Creates custom metadata type records from a comma-separated values (CSV) file.

More details on the usage of various commands, with descriptions, flags and examples, is available in the CLI reference manual and help documentation.

 

Custom Metadata Types Documentation: https://help.salesforce.com/articleView?id=custommetadatatypes_cli.htm&type=5

Salesforce CLI Command Reference:  https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_force_cmdt.htm#cli_reference_force_cmdt

Trailhead unit coming soon !!

0/9000

Hello dear community,

 

I'm creating a sfdx plugin that, for now, scans certain type of metadata to enforces the usage of bypassing practice 

 

https://github.com/jonathanwiesel/sfdx-valkyrie

 

I noticed that when installing using the "sfdx plugins:install" command you can either just indicate the plugin name (to fetch from npm) or a git url:

 

$ sfdx plugins:install myplugin

$ sfdx plugins:install https://github.com/someuser/someplugin

$ sfdx plugins:install someuser/someplugin

 

When fetching from npm (example 1) it will get the latest published version to npm, however when installing from a git url, for example github, which version will it fetch? the latest commit from the master branch? the latest release / tag?

2 commenti
0/9000

Hi All,

I am trying to authenticate with SFDX and JWT for CLI authentication.

I have created certification and all the necessary steps are done.

But I am getting below error.

 

Error: Unexpected arguments:

"stack": "Error: Unexpected arguments: –i, <consumer_key>, –u, <devhubusername>, –f, /Users/Ashish/certificates/server.key, --trace, error\nSee more help with --help\n    at validateArgs (/Users/Ashish/.local/share/sfdx/node_modules/salesforce-alm/node_modules/@oclif/parser/lib/validate.js:10:19)\n    at Object.validate (/Users/Ashish/.local/share/sfdx/node_modules/salesforce-alm/node_modules/@oclif/parser/lib/validate.js:57:5)\n    at Object.parse (/Users/Ashish/.local/share/sfdx/node_modules/salesforce-alm/node_modules/@oclif/parser/lib/index.js:26:7)\n    at AuthJwtGrantCommand.parse (/Users/Ashish/.local/share/sfdx/node_modules/salesforce-alm/node_modules/@oclif/command/lib/command.js:83:41)\n    at AuthJwtGrantCommand.init (/Users/Ashish/.local/share/sfdx/node_modules/salesforce-alm/node_modules/@salesforce/command/lib/sfdxCommand.js:203:44)\nOuter stack:\n    at Function.wrap (/Users/Ashish/.local/share/sfdx/node_modules/salesforce-alm/node_modules/@salesforce/core/lib/sfdxError.js:151:27)\n    at AuthJwtGrantCommand.catch (/Users/Ashish/.local/share/sfdx/node_modules/salesforce-alm/dist/ToolbeltCommand.js:247:46)",

    "warnings": []

}

 

anybody know the solution for it.

TIA

 

@SFDX CLI Plug-in Development @SRIKANTH Shivaramegowda 

1 commento
0/9000

I tried to install a custom CLI Plugin in a CI build in Gitlab, but I wasn't able to whitelist it.

 

I tried to moved the whitelist file as explained here, but I'm still getting the prompt asking for validation:

https://developer.salesforce.com/blogs/2017/10/salesforce-dx-cli-plugin-update.html

 

Was someone able to do it ? I was able to do it in Azure DevOps, not sure what I'm missing in Gitlab.

I'm using the salesforcedx official docker image:

https://hub.docker.com/r/salesforce/salesforcedx

 

It's not the first time I'm struggling to make it work, what about having a Salesforce CLI Environment Variable or a flag to give our own path for the unsignedPluginWhiteList.json file ? Am I the only one thinking this would be easier ?

 

As said in this blog post: "As we get closer to finalizing the developer plugin interface and supporting CLI architecture, we will be providing more information on the steps you, as a plugin developer, need to take to sign your plugins." but this was 2,5 years ago so I've lost hope for it, maybe a env variable or flag would ease this install process.

4 commenti
0/9000

Looking for advice on unit testing. Specifically around org connections and code that requires processing and updating metadata from a Salesforce Org.

 

Can Mocha tests even have a live org connection?

 

Is there a way to mock the org connection data in my plugins?

 

Is it possible to use Jest like we do for LWC or is that just looking for trouble?

0/9000