Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hard delete custom field in Salesforce

Tags:

c#

salesforce

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.

like image 227
Ashish Upadhyay Avatar asked Jun 20 '14 12:06

Ashish Upadhyay


People also ask

What is hard delete in Salesforce?

A Salesforce Bulk Delete or Bulk Hard Delete activity deletes a large number of existing records in a Salesforce endpoint and is intended to be used as a target to consume data in an operation.

How do I delete a custom formula field in Salesforce?

You can only delete custom lookup field and formula field by using these steps: Setup->Select Object Manager Tab->Select that object whose field you want to delete->Select field and relationship->go to drop down menu of that field and choose delete. Please mark it as Best Answer if it helps.


1 Answers

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

like image 112
Rolwin Crasta Avatar answered Sep 24 '22 23:09

Rolwin Crasta