Newer Version Available
renameMetadata()
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 All Data” permission.
Basic Steps for Renaming Metadata Components
Use the following process to rename a metadata component:
- 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.
- 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 is returned that contains information about whether the operation was successful, the name of the renamed component (which is the new name if the renaming was successful), and any errors returned if the operation wasn’t successful.
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 new component full name. |