I have tried to run renameMetadata call from Ant Migration Tool
<target name="1. Rename field on Sandbox">
<sf:renameMetadata username="${sf.Sandbox.username}"
password="${sf.Sandbox.password}"
serverurl="${sf.Sandbox.serverurl}"
deployRoot="../${sf.deploy.dir}/${sf.sandbox.dir}"
rollbackOnError="true"
maxPoll="${sf.maxPoll}"
pollWaitMillis="${sf.pollWaitMillis}">
<metadataType>CustomField</metadataType>
<oldFullName>Object__c.Old_Name__c</oldFullName>
<newFullName>Object__c.New_Name__c</newFullName>
</sf:renameMetadata>
</target>
I know that renameMetadata
CRUD-based call is
Available in API version 30.0 and later.
and I am using the latest version of Ant Migration Tool versioned 45.0, I don't understand why this call is not available for Ant scripting.
Often I need to rename a field on production or promote a text field or picklist to global value set (which already exists) and I am not able to do that. So I have to rename manually each field which I have to promote to already existing global value set, then deploy a new field and then copy field values from all records from old field to new field and then delete the old field. This is very cumbersome process.
I would like to automatize this but I am not sure how this can be achieved.
Can this be automated using Ant Migration Tool? Can this be automated using SFDX CLI? Can this be automated using Tooling API or other means?
I don't want to install afawcett library to work with Metadata API to production.
I have tried to perform a REST call to Tooling API to rename the Custom Field with Id 00N44000006weXa
.
I have been trying many options to achieve this sending PATCH request to /services/data/v45.0/tooling/sobjects/CustomField/00N44000006weXa like
{"DeveloperName" : "New name"}
which was returning me an error
[ {
"message" : "You must provide a valid Metadata field for CustomFieldDefinition",
"errorCode" : "REQUIRED_FIELD_MISSING",
"fields" : [ ]
} ]
When I added
Metadata
field as suggested in the error message,
{"DeveloperName" : "New name", "Metadata":{}}
I received another message
[ {
"message" : "Only the Metadata and FullName fields may be specified on CustomFieldDefinition, or else Metadata must be excluded. Invalid field(s): [DeveloperName]",
"errorCode" : "FIELD_INTEGRITY_EXCEPTION",
"fields" : [ "DeveloperName" ]
} ]
I tried to include FullName
but with no luck
{"DeveloperName" : "New name", "Metadata":{}, "FullName":"Custom_Object__c.New Name"}
since the same error message appears
[ {
"message" : "Only the Metadata and FullName fields may be specified on CustomFieldDefinition, or else Metadata must be excluded. Invalid field(s): [DeveloperName]",
"errorCode" : "FIELD_INTEGRITY_EXCEPTION",
"fields" : [ "DeveloperName" ]
} ]
and when I tried to rename by specifying a different Fullname
,
{"Metadata":{}, "FullName":"Custom_Object__c.NewName__c"}
I received a new error message
[ {
"message" : "Could not resolve standard field's name.",
"errorCode" : "FIELD_INTEGRITY_EXCEPTION",
"fields" : [ ]
} ]
and when I try to specify DeveloperName
in the Metadata
field,
{"Metadata":{"DeveloperName" : "New name"}}
I receive yet another error message
[ {
"message" : "Cannot deserialize instance of complexvalue from VALUE_STRING value New name or request may be missing a required field at [line:1, column:33]",
"errorCode" : "JSON_PARSER_ERROR"
} ]