You need to sign in to do that
Don't have an account?
How to remove custom fields using Metadata API (Bulk delete custom fields)..
Hello,
I want to delete 500+ custom fields. Is there any solution to mass remove custom fields? I have tried with metadata Api using below code. But it gives me below error.
Object with id:04s900000037qo4AAA is InProgress
Error status code: INVALID_CROSS_REFERENCE_KEY
Error message: In field: members - no CustomField named Custom_Field__c found
Object with id:04s900000037qo4AAA is Error
Below is the code:
public void deleteCustomField(String fullname) throws Exception
{
CustomField customField = new CustomField();
customField.setFullName(fullname);
UpdateMetadata updateMetadata = new UpdateMetadata();
updateMetadata.setMetadata(customField);
updateMetadata.setCurrentName(fullname);
AsyncResult[] asyncResults = metadataConnection.delete(new Metadata[] {customField});
long waitTimeMilliSecs = ONE_SECOND;
do
{
printAsyncResultStatus(asyncResults);
waitTimeMilliSecs *= 2;
Thread.sleep(waitTimeMilliSecs);
asyncResults = metadataConnection.checkStatus(new String[]{asyncResults[0].getId()});
} while (!asyncResults[0].isDone());
printAsyncResultStatus(asyncResults);
}
private void printAsyncResultStatus(AsyncResult[] asyncResults) throws Exception {
if (asyncResults == null || asyncResults.length == 0 || asyncResults[0] == null) {
throw new Exception("The object status cannot be retrieved");
}
AsyncResult asyncResult = asyncResults[0]; //we are creating only 1 metadata object
if (asyncResult.getStatusCode() != null) {
System.out.println("Error status code: " +
asyncResult.getStatusCode());
System.out.println("Error message: " + asyncResult.getMessage());
}
System.out.println("Object with id:" + asyncResult.getId() + " is " +
asyncResult.getState());
}
Is there any other solution (any app) to removing custom fields?
Thanks in advance,
Dhaval Panchal
Finally i got solution using below descructiveChanges.xml file
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>codepkg</fullName>
<types>
<members>MyCustomObject__c.Custom_Field_del__c</members>
<name>CustomField</name>
</types>
<types>
<members>MyCustomObject__c.Custom_Field2__c</members>
<name>CustomField</name>
</types>
<version>17.0</version>
</Package>
All Answers
Hi,
You can use Force.com IDE to delete custom fields using Metadata API.
see This Link :- Metadata & the Metadata API
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.
Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator
My Blog:- http://mrjavascript.blogspot.in/
I am using Force.com in eclipse. Do you have any steps to do this process?
Hi,
Below is the steps as per your requirements
1. Log in Eclipse in your own project in which you want to delete the fields.
2. Double click and Open the Metadata for the Object whose fields you want to delete.
3. When the metadata is shown up. find the tag and select all those which u want to delete.
4. Click on Backspace to delete and deploy to server so as it is reflected in Production or Sandbox from where you copied.
Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator
My Blog:- http://mrjavascript.blogspot.in/
I did same thing, I have removed tag <fields></fields> but problem is that once i remove this tag, and try to save (locally) it refresh it from server again. So I am not able to remove any fields. I have tried so many times but it is not reflecting on server (I am using developer edition).
remove the tag, and try to save to server. Not refresh from server.
See below screenshot.
https://docs.google.com/file/d/0B6cPMtpRoi9FTnZqMmdHaDZpU3c/edit?usp=sharing
I am following below steps.
1. Open xml file
2. Select field tag to remove
3. Save (local)
4. Then save to server.
5. Also tried deploy to server.
I thing i have to check my ide settings.
I was on the same situation ....One thing is sure ,from eclipse you cannot do.
Go to other path rather than eclipse.
May be From Ant we can do it.......and there are other ide, but i am not confirm about it.
I tried with descructiveChanges.xml, and it successfully deletes objects but not able to remove custom fields. Even I am getting below success message in console.
undeployCode:
[sf:deploy] Request for a deploy submitted successfully.
[sf:deploy] Request Id for the current deploy task: 09S90000000EhvZEAS
[sf:deploy] Waiting for server to finish processing the request...
[sf:deploy] Request Status: Completed
[sf:deploy] Finished request 09S90000000EhvZEAS successfully.
BUILD SUCCESSFUL
Total time: 15 seconds
But when I check in salesforce.com it is not deleted.
below is my descructiveChanges.xml file
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>codepkg</fullName>
<types>
<members>Custom_Field1__c</members>
<members>Custom_Field2__c</members>
<name>CustomField</name>
</types>
<version>17.0</version>
</Package>
Finally i got solution using below descructiveChanges.xml file
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>codepkg</fullName>
<types>
<members>MyCustomObject__c.Custom_Field_del__c</members>
<name>CustomField</name>
</types>
<types>
<members>MyCustomObject__c.Custom_Field2__c</members>
<name>CustomField</name>
</types>
<version>17.0</version>
</Package>
Is it possible to add all the 500 custom fields into this XML automatically OR you need to generate this XML manually?
You can create csv files with object and field list then use below java codes to generate xml file.
Hi Pooja,
I hope this is the standard java code i can always use for Object/field files? The reason to ask i do not know java :)
Thanks!
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>codepkg</fullName>
<types>
<members>MyCustomObject__c.Custom_Field_del__c</members>
<name>CustomField</name>
</types>
<types>
<members>MyCustomObject__c.Custom_Field2__c</members>
<name>CustomField</name>
</types>
<version>17.0</version>
</Package>