12.07.2015 Views

Database.com Metadata API Developer's Guide - Salesforce.com

Database.com Metadata API Developer's Guide - Salesforce.com

Database.com Metadata API Developer's Guide - Salesforce.com

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CRUD-Based Callsread<strong>Metadata</strong>()PermissionsYour client application must be logged in with the “Modify All Data” permission.Basic Steps for Reading <strong>Metadata</strong> ComponentsUse the following process to read metadata <strong>com</strong>ponents:1. Determine the metadata type of the <strong>com</strong>ponents you want to read, and the fullName of each <strong>com</strong>ponent to read. See<strong>Metadata</strong> for more details on the fullName field. You can read only <strong>com</strong>ponents of the same type in a single call.2. Invoke the read<strong>Metadata</strong>() call. For the first argument, pass in the name of the metadata type. The metadata type mustmatch one of the values returned by the describe<strong>Metadata</strong>() call. For the second argument, pass in an array of fullnames corresponding to the <strong>com</strong>ponents you wish to get. The full names must match one or more full names returned bythe list<strong>Metadata</strong>() call.3. A ReadResult is returned that contains an array of <strong>Metadata</strong> <strong>com</strong>ponents. Cast each returned <strong>Metadata</strong> object to themetadata type you specified in the call to get the <strong>com</strong>ponent’s properties.Sample Code—Javapublic void readCustomObjectSync() {try {ReadResult readResult = metadataConnection.read<strong>Metadata</strong>("CustomObject", new String[] {"MyCustomObject1__c", "MyCustomObject2__c" });<strong>Metadata</strong>[] mdInfo = readResult.getRecords();System.out.println("Number of <strong>com</strong>ponent info returned: "+ mdInfo.length);for (<strong>Metadata</strong> md : mdInfo) {if (md != null) {CustomObject obj = (CustomObject) md;System.out.println("Custom object full name: "+ obj.getFullName());System.out.println("Label: " + obj.getLabel());System.out.println("Number of custom fields: "+ obj.getFields().length);System.out.println("Sharing model: "+ obj.getSharingModel());} else {System.out.println("Empty metadata.");}}} catch (ConnectionException ce) {ce.printStackTrace();}}ArgumentsNamemetadataTypefullNamesTypestringstring[]DescriptionThe metadata type of the <strong>com</strong>ponents to read.Array of full names of the <strong>com</strong>ponents to read.Limit: 10.You must submit arrays of only one type of <strong>com</strong>ponent. For example, you could submitan array of 10 custom objects or 10 profiles, but not a mix of both types.ResponseReadResult49

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!