0

To my dismay I find that, according to the documentation, post-install scripts are not supported for Unlocked Packages.

Now I am looking for a (hopefully comparably painless) way to make up for that deficiency. My Unlocked Package needs to add or update one ore more rows in an existing custom object (a kind of configuration table).

Any suggestions will be welcome.

1
  • If possible use custom metadata type records to hold your config. These can be packaged.
    – Phil W
    Jun 17, 2021 at 21:45

1 Answer 1

2

We had few post deployment steps like yours.

Adding data, use its Id as lookup and add another objects data.

With the advent of SFDX CLI, it got easier.

You can use force:apex:execute if it's a simple data creation.

However, if you want to load huge data which may not be feasible with apex because of governor limits try force:data:tree:import, it allows us to have multiple json files(200 within each file). In this way you need to define sequence in data plan json, so that it automatically picks in that sequence (so that lookup geta proper ids also). Example of this, you can find here - https://github.com/trailheadapps/ebikes-lwc/tree/main/data

8
  • I do not completely understand your proposal: can you be a little more specific and explain in more detail the process of getting the Unlocked Package together with the necessary data rolled out to the target org.
    – willeg
    Jun 17, 2021 at 21:26
  • 1
    @willeg as Use said, the ideal situation is to use the data tree import command to add data post-install. Failing that, you should be able to create a configuration link to allow manual data creation after install.
    – sfdcfox
    Jun 17, 2021 at 22:09
  • @willeg - Are you talking about Managed 2Gp packages? or unlocked packages?
    – Ysr Shk
    Jun 18, 2021 at 4:36
  • 1
    Try below link where it adds classes in the sfdx-project.json - developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/…
    – Ysr Shk
    Jun 18, 2021 at 4:37
  • 1
    @willeg If I were you, I'd give it a try.
    – Ysr Shk
    Jun 18, 2021 at 10:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .