Newer Version Available

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

readMetadata()

Returns one or more metadata components from your organization synchronously.

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 All Data or Modify Metadata Through Metadata API Functions permission.

If a user requires access to metadata but not to data, you can enable the Modify Metadata Through Metadata API Functions permission to give the access the user needs without providing access to org data.

Note

Basic Steps for Reading Metadata Components

Use the following process to read metadata components:

  1. Determine the metadata type of the components you want to read, and the fullName of each component to read. See Metadata for more details on the fullName field. You can read only components of the same type in a single call.
  2. 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. The full names must match one or more full names returned by the listMetadata() call.
  3. 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}

Arguments

Name Type Description
metadataType string The metadata type of the components to read.
fullNames string[] Array of full names of the components to read.

Limit: 10. (For CustomMetadata and CustomApplication only, the limit is 200.)

You must submit arrays of only one type of component. For example, you can submit an array of 10 custom objects or 10 profiles, but not a mix of both types.

Response

ReadResult