1

Using Metadata API, I deployed a destructive change that removed some unused Apex classes and Custom objects. I then verified on the sandbox that they were indeed deleted.

I then created a new version of an unlocked package that was installed in the sandbox which also removed the un needed Apex classes and custom objects from the package folders.

When I install this new package, it installs perfectly. Upon reviewing the package in package manager under "Metadata components Included in package" section, I see that there is a lingering reference to a custom object layout which had been deleted as part of my metadata destructive change above.

I know I can delete that in the UI and move on. However the behavior I was expecting was the absence of this layout since that custom object was deleted and is no longer present in the org and ideally I would want this all to be programmatic and not on the UI.

1 Answer 1

2

As per the documentation, for more recent API versions you can actually specify the behaviour for deletions as part of your package update using the --upgradetype parameter when installing unlocked package versions:

In API version 45.0 and later (salesforcedx plug-in for Salesforce CLI version 45.0.9 or later), you can specify what happens to removed metadata during package upgrade. Use the force:package:install command’s -t | --upgradetype parameter, specifying one of these values:

Delete specifies to delete all removed components, except for custom objects and custom fields, that don’t have dependencies.

DeprecateOnly specifies that all removed components must be marked deprecated. The removed metadata exists in the target org after package upgrade, but is shown in the UI as deprecated from the package. This option is useful when migrating metadata from one package to another.

Mixed (the default) specifies that some removed components are deleted, and other components are marked deprecated. For more information on hard-deleted components, see Metadata Coverage.

I note that the metadata coverage lists Layouts as hard-deleted and thus should have disappeared.

Since it has not, I suggest you check the API version defined in your sfdx-project.json and update it to a newer version if necessary.

You must log in to answer this question.

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