You need to sign in to do that
Don't have an account?

Rename API name of existing custom fields
I am trying to rename existing field's API name. I know that before that I have to remove all references from class, VF pages..etc. Currently I am trying to fetch all references like classes and field metadata (xml file) in VS code and trying to deploy back with the updated name but it is creating new fields instead of overwriting the existing field. Can any one let me know that how should I proceed? shall I have to remove all references in the org manually then change the field API name. Post that put back all changes again manually?
1.Removal of the usage of Field/Object in the metadata, i.e Apex Classes, Triggers, Visualforce Pages, Visualforce Components etc. will be required, and then the components will be needed to be changed in order to refer to the new API Name of the Field/Object.
2.If there are any Webservice Callouts which are being carried out via Apex Code, you will need to first remove the usage, and then change the API names in the code.
As you already know,we can search all the references in VS code.Once,you have all the list of components where you have referenced the field,you need remove the field refences.
Then,you need to login to the salesforce and update the API name in the Org which can be possible in the Production as well.
Once,you have done the update in the UI then you can update the code in VS code and deploy it into the Production.
Hope this is clear now.
Thank you!
All Answers
Greetings!
Yes,it will create the new custom field as we are trying to change the API name of the field based on which the field will search for the existing field whenever we try to update the API name using any other tool.
However,you can search for the references using VS code and remove the references of the field and go ahead and update the API name of the field manually in the org and then update it with the New API name using the VS code.
Reference:https://help.salesforce.com/articleView?id=000314907&type=1&mode=1
Kindly mark it as best answer if it helps so that it can help others in the future.
Warm Regards,
Shirisha Pathuri
1.Removal of the usage of Field/Object in the metadata, i.e Apex Classes, Triggers, Visualforce Pages, Visualforce Components etc. will be required, and then the components will be needed to be changed in order to refer to the new API Name of the Field/Object.
2.If there are any Webservice Callouts which are being carried out via Apex Code, you will need to first remove the usage, and then change the API names in the code.
As you already know,we can search all the references in VS code.Once,you have all the list of components where you have referenced the field,you need remove the field refences.
Then,you need to login to the salesforce and update the API name in the Org which can be possible in the Production as well.
Once,you have done the update in the UI then you can update the code in VS code and deploy it into the Production.
Hope this is clear now.
Thank you!
If you want to do this on Production, than please follow the below steps:
- Remove all the references from the components using the vs code.
- Add the fields that you want to replace in the postdestructivechanges.xml file.
File name should be destructiveChangesPost. Sample code for this file is as below: What it will do is, it will delete the old fields after the deployment. Please make sure this xml file is kept at the same place where package.xml is stored.Let me know if you need any other help.
Thanks,
Abhishek Bansal.