Explore Courses Blog Tutorials Interview Questions
0 votes
in Salesforce by (11.9k points)

I am having problem in deleting custom fields permanently.

Like for e.g. I have created a custom field in Contact entity with name "Newsletter" which Salesforce internaly stores as "Newsletter__c" as custom field.

Then I use the below code to delete custom field of contact.

var cstField = new CustomField


  type = FieldType.Checkbox,

  fullName = "Contact.Newsletter__c"


// Delete the object

var r = metaService.delete(new Metadata[] { cstField })[0];

The above code deletes the custom field, but keeps it under "DeletedFields" category where you can again "Erase" or "Undelete" the custom field. These custom fields are deleted automatically after 15 days.

I want to delete the custom fields from these category also as if I again create cf with same name SF gives error like "Already exists".

I tried purgeOnDelete option too while deploying but no luck so far.

1 Answer

0 votes
by (32.1k points)
edited by

A hidden gem in the Metadata API deploy operation which takes a DeployOptions structure, in it is a purgeOnDelete setting that will do what all you actually need!

Are you interested in learning Salesforce from the basics! Refer to this video on salesforce provided by Intellipaat:

So, according to purgeOnDelete, the deleted components in the destructiveChanges.xml manifest file aren't saved in the recycle bin. Instead, they instantly become eligible for deletion. This particular field is accessible in from  API version 22.0 and further. But, this option works only in the Sandbox organizations or Developer Edition and doesn't work in production organizations.

However, with few java skills, you can create a new deploy Ant Task by extending the current one, to expose the attribute to your Ant build scripts.

Enroll in this Salesforce Certification to start your journey today!

Related questions

Browse Categories