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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CRUD-Based Callscreate<strong>Metadata</strong>()SyntaxSaveResult[] = metadatabinding.create<strong>Metadata</strong>(<strong>Metadata</strong>[] metadata);UsageUse the create<strong>Metadata</strong>() call to add one or more metadata <strong>com</strong>ponents to your organization. This call executessynchronously, meaning the call returns only when the operation <strong>com</strong>pletes.This call can be used to create any of the objects that extend <strong>Metadata</strong>. For more details, see <strong>Metadata</strong> Components andTypes.VersionAvailable in <strong>API</strong> version 30.0 and later.PermissionsYour client application must be logged in with the “Modify All Data” permission.Required FieldsRequired fields are determined by the metadata <strong>com</strong>ponents being created. For more information about specific <strong>com</strong>ponenttypes, see <strong>Metadata</strong> Components and Types.Valid Data ValuesYou must supply values that are valid for the field’s data type, such as integers for integer fields (not alphabetic characters). Inyour client application, follow the data formatting rules specified for your programming language and development tool (yourdevelopment tool handles the appropriate mapping of data types in SOAP messages).String ValuesWhen storing values in string fields, the <strong>API</strong> trims any leading and trailing whitespace. For example, if the value of a labelfield is entered as "MyObject ", the value is stored in the database as "MyObject".Basic Steps for Creating <strong>Metadata</strong> ComponentsUse the following process to create metadata <strong>com</strong>ponents:1. Design an array and populate it with the <strong>com</strong>ponents that you want to create. All <strong>com</strong>ponents must be of the same type.2. Call create<strong>Metadata</strong>() with the <strong>com</strong>ponent array passed in as an argument.3. A SaveResult object is returned for each <strong>com</strong>ponent you tried to create. It contains information about whether theoperation was successful, the name of the <strong>com</strong>ponent created, and any errors returned if the operation wasn’t successful.Sample Code—Javapublic void createCustomObjectSync() {try {CustomObject co = new CustomObject();String name = "MyCustomObject1";co.setFullName(name + "__c");co.setDeploymentStatus(DeploymentStatus.Deployed);co.setDescription("Created by the <strong>Metadata</strong> <strong>API</strong>");co.setEnableActivities(true);co.setLabel(name + " Object");co.setPluralLabel(co.getLabel() + "s");co.setSharingModel(SharingModel.ReadWrite);CustomField nf = new CustomField();47

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

Saved successfully!

Ooh no, something went wrong!