Newer Version Available

This content describes an older version of this product. View Latest

renameMetadata()

Renames a metadata component in your organization synchronously.

Syntax

1SaveResult = metadataConnection.renameMetadata(string metadataType, String oldFullname, String newFullname);

Usage

Use the renameMetadata() call to rename one metadata component in your organization. This call executes synchronously, meaning the call returns only when the operation completes.

You can use this call to rename any of the objects that extend Metadata. For more details, see Metadata Components and Types.

Version

Available in API version 30.0 and later.

Permissions

Your client application must be logged in with the Modify Metadata Through Metadata API Functions or Modify All Data permission.

If a user requires access to metadata but not to data, enable the Modify Metadata Through Metadata API Functions permission. Otherwise, enable the Modify All Data permission.

Note

Basic Steps for Renaming Metadata Components

Use this process to rename a metadata component.

  1. Determine the metadata type of the component you want to rename, its current full name, and the new full name. See Metadata for more details on the fullName field.
  2. Invoke the renameMetadata() call. For the first argument, pass in the name of the metadata type. Pass in the old full name as the second argument and the new full name as the last argument.

    A SaveResult object that contains information about whether the operation was successful is returned. If successful, the object contains the name of the renamed component, which is the new name. If it wasn’t successful, the object returns any errors.

Sample Code—Java

1public void renameCustomObjectSync() {
2 try {
3    SaveResult[] results = metadataConnection.renameMetadata(
4        "CustomObject", "MyCustomObject1__c","MyCustomObject1New__c");
5    for (SaveResult r : results) {
6    	if (r.isSuccess()) {
7    		System.out.println("Renamed component: " + r.getName());
8    	}
9    	else {
10    		System.out.println("Errors were encountered while renaming " + r.getName());
11    		for(Error e : r.getErrors()) {
12    			System.out.println("Error message: " + e.getMessage());
13    			System.out.println("Status code: " + e.getStatusCode());
14    		}
15    	}
16    }
17  } catch (ConnectionException ce) {
18    ce.printStackTrace();
19  } catch (InterruptedException ie) {
20    ie.printStackTrace();
21  }
22}

Arguments

Name Type Description
metadataType string The metadata type of the components to rename.
oldFullName string The current component full name.
newFullName string The full name of the new component.

Response

SaveResult