Newer Version Available
readMetadata()
Syntax
1ReadResult = metadataConnection.readMetadata(string metadataType, string[] fullNames);Usage
Use the readMetadata() call to retrieve any component that extends Metadata. All components must be of the same type in the same call. For more details, see Metadata Components and Types.
This call executes synchronously, which means that the call returns only when the operation completes.
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.
Basic Steps for Reading Metadata Components
Use the following process to read metadata components:
- Determine the metadata type of the components you want to read and the fullName of each component to read.
The full names must match one or more full names returned by the listMetadata() call, which includes namespace prefixes. If you obtain the fullName from a package manifest file, and the component has a namespace prefix, prepend the namespace prefix to the fullName. Use this syntax: namespacePrefix__ComponentName. For example, for the custom object component MyCustomObject__c and the namespace MyNS, the fullName is MyNS__MyCustomObject__c. For more information about the fullName field, see Metadata.
You can read only components of the same type in a single call.
- Invoke the readMetadata() call. For the first argument, pass in the name of the metadata type. The metadata type must match one of the values returned by the describeMetadata() call. For the second argument, pass in an array of full names corresponding to the components you wish to get.
- A ReadResult is returned that contains an array of Metadata components. Cast each returned Metadata object to the metadata type you specified in the call to get the component’s properties.
Sample Code—Java
1public void readCustomObjectSync() {
2 try {
3 ReadResult readResult = metadataConnection
4 .readMetadata("CustomObject", new String[] {
5 "MyCustomObject1__c", "MyCustomObject2__c" });
6 Metadata[] mdInfo = readResult.getRecords();
7 System.out.println("Number of component info returned: "
8 + mdInfo.length);
9 for (Metadata md : mdInfo) {
10 if (md != null) {
11 CustomObject obj = (CustomObject) md;
12 System.out.println("Custom object full name: "
13 + obj.getFullName());
14 System.out.println("Label: " + obj.getLabel());
15 System.out.println("Number of custom fields: "
16 + obj.getFields().length);
17 System.out.println("Sharing model: "
18 + obj.getSharingModel());
19 } else {
20 System.out.println("Empty metadata.");
21 }
22 }
23 } catch (ConnectionException ce) {
24 ce.printStackTrace();
25 }
26}