How do I make sure that the packaging org is building the managed package only based on the files that I have in my source control system?

We recently moved to SFDX and part of the deployment process involved converting the source code to MDAPI and push all the code to the packaging org. This step adds any new object, like a new class, to the objects included in our managed package.

However, it will not remove any objects that have been added to the managed package previously (even the non-released ones, that have a "delete" link attached in the UI), even if they do not have a corresponding source file. This makes it difficult to automate this process as we would always have to manually check that there are no extraneous objects in the list of objects included in the managed package.

Having unwanted objects can happen pretty frequently for us since we also use the packaging org to build beta versions of the MP and these versions might include files that then do not end up in the release version.

1 Answer 1


I'm assuming, since you discuss a packaging org, that this is 1GP.

With 1GP the "source of truth" is the packaging org, not your version control system. As such, you'll have to script this yourself (by comparing metadata content on the packaging org selected for packaging with the source from your VCS), just like you would have done before moving to sfdx. This will be non-trivial. Of course, you'll also need to worry about whether this would actually be deleting something that was previously included in a release, and in that case you'll need to have packaged metadata deletion enabled for your package.

We have lived with the pain of doing this by hand for the last 8 years. We also live with having to manually add new metadata to the package's content when there's no automatic addition due to dependency resolution.

It is only with 2GP that the "source of truth" is your version control system (well, actually the file system holding the checked out metadata in context of the package version creation execution, but that's just splitting hairs). I very much look forward to when we can finally migrate our 1GP to be a 2GP to finally remove this frustrating part of ISV developer life (amongst others) and benefit fully, across all our packages, from the 2GP improvements.

BTW, with 1GPs, you can still use the modern "source" format (without any need to use MDAPI conversion) by using sfdx force:source:deploy against specific package directory folder(s). The "source" format is preferred, especially with how it structures objects with many separate files, and is the right format to use for 2GP too.

  • That makes sense, thank you! That is frustrating. Commented Jan 5, 2022 at 23:20

You must log in to answer this question.

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