9

I had created a number of packages and package versions in order to help prepare for moving our metadata to packages in production. At some point, I accidentally pulled in a bunch of metadata that I did not intend to include in the package, and then I ran a script to remove those extra files, and ended up deleting more than I meant to.

I can't roll back to my last commit, because it won't have all the files, so creating a new version will cause metadata to be removed that I don't want removed. So, ultimately, what I'm looking for is a way to recover the metadata in the last version of my Unlocked Package. I already tried retrieving the package using force:source:retrieve with a package name, but I got an error saying the package doesn't exist.

Is there any way to retrieve the metadata from the package version so I can reset my repo back to the last good version that I had created?

5
  • 2
    I haven't played around with unlocked packages much, but coming at this from the git side of things: everything you've done is tracked and uncommitted/unstaged in your IDE, correct? I'm not sure the # of files you're dealing with, but git checkout --patch will allow you to checkout your files and choose whether to discard or keep your local changes you haven't committed yet. Could keep what you want and discard the accidental deletions. Likewise, some combo of git stash and reverting back to your original commit might work in your favor here Commented Jan 21, 2020 at 16:53
  • Do you have the latest version installed on any org by any means ? Commented Jan 21, 2020 at 16:56
  • 3
    It isn't very elegant but you may be able to use force:package:install -p 04t... to push that specific package version with the contents you need into an empty org and then retrieve all of the metadata from the new org.
    – Mark Pond
    Commented Jan 21, 2020 at 17:06
  • @KrisGoncalves I didn't know about that, I'll try it, but there's potentially thousands of files to deal with. I was hoping I could just retrieve the saved metadata somehow.
    – sfdcfox
    Commented Jan 21, 2020 at 21:59
  • @MohithShrivastava It's installed in a sandbox currently, along with five or so other unlocked packages and all of our "soup".
    – sfdcfox
    Commented Jan 21, 2020 at 22:01

1 Answer 1

12

The package can now be retrieved using one of of the below approach

sfdx force:source:retrieve -n <package name>

or if you need package.xml and in metadata API format use below

sfdx force:mdapi:retrieve --packagenames=<package name> -r <directory path to retrieve>

Looks like the team has fixed the issue with an unlocked package. Reach out if you see any issue doing this.

2
  • I've successfully used mdapi:retrieve for unlocked package downloads. However, this doesn't work directly against the DevHub. It still requires the detour of creating an org and installing the package version (as stated by Mark Pond above), if one has not already access to an org with the installed version. Or have I missed anything? Commented Aug 4, 2021 at 9:20
  • When I run 'sfdx force:source:retrieve -n <package name>' this command getting "ERROR running force:source:retrieve: INVALID_CROSS_REFERENCE_KEY: invalid cross reference id". Is there anyone who faced the same issue?
    – SDK
    Commented Jan 7, 2022 at 9:41

You must log in to answer this question.

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