Newer Version Available
update()
This call can be used to update any of the objects that extend Metadata. For more details, see Metadata Components and Types.
Syntax
1AsyncResult[] = metadataConnection.update(UpdateMetadata[] metadata);Usage
Use this call to update one or more components. This call is analogous to the ALTER TABLE statement in SQL.
Version
This call is available in API version 30.0 and earlier only. This call is not available in API version 31.0 and later. Use updateMetadata() instead to update metadata components or renameMetadata() to rename a metadata component.
Permissions
Your client application must be logged in with the “Modify All Data” permission.
Required Fields
You must supply values for all the required fields in the component.
Valid Field Values
You must supply values that are valid for the field’s data type, such as integers for integer fields (not alphabetic characters). In your client application, follow the data formatting rules specified for your programming language and development tool (your development tool handles the appropriate mapping of data types in SOAP messages).
String Values
When storing values in string fields, the API trims any leading and trailing white space. For example, if the value of a label field is entered as "MyObject " the value is stored in the database as "MyObject".
Basic Steps for Updating Metadata Components
- Create an array of UpdateMetadata components and populate it with the components you wish to update. All components must be of the same type.
- Invoke the update() call, passing in the array of metadata components to update.
- An AsyncResult object is returned for each component you try to update, and is updated with status information as the operation moves from a queue to completed or error state. In a loop, call checkStatus() until the status values in AsyncResult indicate that all the update operations are completed. Start with a wait time of one second between iterations of checkStatus() calls, and double the wait time each time you make a subsequent call.
Sample Code—Java
1swfobject.registerObject("clippy.codeblock-1", "9");
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17public void updateCustomObject() {
18 try {
19 CustomObject co = new CustomObject();
20 String name = "MyCustomObject";
21 co.setFullName(name + "__c");
22 co.setDeploymentStatus(DeploymentStatus.Deployed);
23 co.setDescription("Created by the Metadata API");
24 co.setEnableActivities(true);
25 co.setLabel(name + " Object");
26 co.setPluralLabel(co.getLabel() + "s");
27 co.setSharingModel(SharingModel.ReadWrite);
28
29 CustomField nf = new CustomField();
30 nf.setType(FieldType.Text);
31 nf.setLabel(co.getFullName() + " Name");
32
33 co.setNameField(nf);
34
35 UpdateMetadata updateMetadata = new UpdateMetadata();
36 updateMetadata.setMetadata(co);
37 updateMetadata.setCurrentName("TheCurrentName");
38
39 AsyncResult[] ars = metadataConnection.update(new UpdateMetadata[]
40 { updateMetadata });
41 AsyncResult asyncResult = ars[0];
42 // set initial wait time to one second in milliseconds
43 long waitTimeMilliSecs = 1000;
44 while (!asyncResult.isDone()) {
45 Thread.sleep(waitTimeMilliSecs);
46 // double the wait time for the next iteration
47 waitTimeMilliSecs *= 2;
48 asyncResult = metadataConnection.checkStatus(
49 new String[] {asyncResult.getId()})[0];
50 System.out.println("Status is: " + asyncResult.getState());
51 }
52
53 if (asyncResult.getState() != AsyncRequestState.Completed) {
54 System.out.println(asyncResult.getStatusCode() + " msg: " +
55 asyncResult.getMessage());
56 }
57 } catch (InterruptedException ie) {
58 ie.printStackTrace();
59 } catch (ConnectionException ce) {
60 ce.printStackTrace();
61 }
62}Arguments
| Name | Type | Description |
|---|---|---|
| metadata | UpdateMetadata[] | Array of one or more UpdateMetadata data structures that represent the components you wish to update. Limit: 10. You must submit arrays of only one type of component. For example, you could submit an array of 10 custom objects or 10 profiles, but not a mix of both types. |
UpdateMetadata
One or more UpdateMetadata objects are defined in the metadata argument. This object can be used to update any of the objects that extend Metadata. For more details, see Metadata Components and Types. Each UpdateMetadata object has the following fields:
| Field | Field Type | Description |
|---|---|---|
| currentName | string | The API name of the component or field before the update. For example, if you wanted to update a CustomObject named Foo, the value of this field would be Foo__c. This value is supplied because this call may change the name, and the value here provides mapping. |
| metadata | Metadata | Full specification of the component or field you wish to update. |