DID THIS ARTICLE SOLVE YOUR ISSUE?
Let us know so we can improve!
Let us know so we can improve!
renameMetadata()Renames a metadata component in your organization synchronously.
1SaveResult = metadataConnection.renameMetadata(string metadataType, String oldFullname, String newFullname);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.
Available in API version 30.0 and later.
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
Use this 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 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.
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}