I have tried to run renameMetadata call from Ant Migration Tool

<target name="1. Rename field on Sandbox">
    <sf:renameMetadata username="${sf.Sandbox.username}"

but received an error enter image description here

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",
  "fields" : [ ]
} ]

enter image description here 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]",
  "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]",
  "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.",
  "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"
} ]

1 Answer 1


Metadata API has 2 formats.

  • File-Based Calls
  • CRUD-Based Calls

RenameMetadata is crud based called and not File-Based calls. Thus you won't be able to use force.com migration tool aka ANT or workbench for this purpose.

The easiest way to use crud based call is to use Metadata API Wsdl. You can download it by navigating it from Setup->API->Metadata WSDL

Now it's a Soap Call, so we need a soap client to do a callout. I use this amazing chrome extension wizdler to do soap calls.

When you open wsdl in chrome, Wizdler shows you an option to do renameMetadataCallout. RenameMetadata

Just click it and provide the proper information and click Request. Bam done fieldApiName changed.

Endpoint: https://mydomainmy.salesforce.com/services/Soap/m/45.0

<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
        <SessionHeader xmlns="http://soap.sforce.com/2006/04/metadata">

        <renameMetadata xmlns="http://soap.sforce.com/2006/04/metadata">


<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://soap.sforce.com/2006/04/metadata">

If you provide same request using HttpRequest in apex and set header as "SOAPAction" you can do the same callout from native Salesforce.

I don't fancy using tooling api, as tooling API cant be used in production to alter metadata.

  • interesting, so this can be possibly automatized
    – Patlatus
    Commented May 26, 2019 at 14:00
  • @Patlatus yeah it can be Commented May 26, 2019 at 17:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .