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?

  • 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 – Kris Goncalves Jan 21 '20 at 16:53
  • Do you have the latest version installed on any org by any means ? – Mohith Shrivastava Jan 21 '20 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 Jan 21 '20 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 Jan 21 '20 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 Jan 21 '20 at 22:01

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.

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.