Hard delete custom field in Salesforce
Asked Answered
S

1

12

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.

Sherri answered 20/6, 2014 at 12:31 Comment(2)
Not sure if you can do that. My approach has been to rename fields before deleting them.Daze
I tried lot of methods for hard deleting custom fields, but still unable to succeed. Renaming is good option, but if the same custom field is created thrice then renaming every time and deleting them would be overhead. Not sure that there cant be any method to hard delete. Anyways thanks for your try.Sherri
W
3

purgeOnDelete. If true, the deleted components in the destructiveChanges.xml manifest file aren't stored in the Recycle Bin. Instead, they become immediately eligible for deletion. This field is available in API version 22.0 and later. This option only works in Developer Edition or sandbox organizations; it doesn't work in production organizations. Extending Salesforce Migration Tool to Support PurgeOnDelete.. For some reason this excellent feature has still not been exposed by the Salesforce Migration Tools via the sf:deploy Ant Task. However with a bit of Java skills you can create a new deploy Ant Task by extending the current one, to expose the attribute to your Ant build scripts, for example...

Prebuilt ant-salesforce.jar with deploypurge in it. You can download a modified ant-salesforce.jar here from the FinancialForce.com Developers Github repo (be warned this is API v22.0, though you can use it to deploy code at any version).

Building your own extended ant-salesforce.jar. If you want rebuild a new version, then you need to download this Java class, compile it, unzip the ant-salesforce.jar (rename .jar to .zip), put it in and zip it back up again and your all set!

Refer : https://salesforce.stackexchange.com/questions/12709/hard-delete-objects-using-the-force-com-migration-tool

Weidner answered 5/11, 2014 at 8:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.