6

Is there anyway to specify (using Salesforce DX) that the package I want to create includes a post install script?

https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_force_package1.htm#cli_reference_force_package1

I don't see any parameters in the command to include it. If you create it manually it works fine, but just was wondering if it is a missed feature in Salesforce DX cli.

1

The postinstall script is set as part of the package.xml file, which if you're using SFDX for development you'll probably be automatically generating as part of your build script using sfdx force:source:convert.

We use a tool in our build runner called xmlstarlet which we use to inject the postInstallClass script name into the package.xml file before it is deployed to the packaging org and the package is created.

xml ed --inplace -N sfdc="http://soap.sforce.com/2006/04/metadata" \
       --subnode "/sfdc:Package" --type elem -n "postInstallClass" -v "PostInstall" \
       ./mdapi-source/package.xml

This adds the following element to the package.xml

<postInstallClass>PostInstall</postInstallClass>

Alternatively you could do this using a find and replace tool like sed or by maintaining the package.xml in source.

An issue has been logged against the CLI to allow this and other package related attributes (uninstall script, release notes link etc.) to be specified in the force:source:convert command.

  • Thanks - this is a great tip. We needed something ideally without any external tools, so I'm using the following in our windows based script (bit of a bodge but works well enough for us): powershell -Command "(gc mdapi_output_dir/package.xml) -replace '</Package>', '<postInstallClass>PostInstallScript</postInstallClass></Package>' | Out-File -encoding UTF8 mdapi_output_dir/package.xml". Linux based would of course be trivial using sed. – berry120 Mar 19 at 15:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.