Best practices in using Salesforce Metadata API
-
Upload
sanchit-dua -
Category
Technology
-
view
918 -
download
3
description
Transcript of Best practices in using Salesforce Metadata API
Presentation Title Date
Copyright Salesforce 2014. Legal Terms and more here.
Best practices in using SalesforceMeta Data APINaveen GabraniCEO Astrea IT Servicesngabrani At astreait.com@ngabrani
Sanchit DuaSenior Software Developer Astrea IT Services@Sanchit1
Naveen GabraniCEO Astrea IT Servicesngabrani At astreait.com
Presentation Title Date
Copyright Salesforce 2014. Legal Terms and more here.
Sanchit DuaSenior Software Developer Astrea IT Services
Agenda1. What is Metadata2. What is Metadata API3. How can I access it?4. Two type of Metadata operations5. Common applications of the Metadata API6. Development Scenarios and correct implementation7. Best Practices and common issues
Presentation Title Date
Copyright Salesforce 2014. Legal Terms and more here.
What is Metadata Data: Some thing that is stored in database (accounts) Metadata: Configuration/Code describes how the application looks Shapes the functionality of your specific applications Controls logic and presentation
What is Metadata API Programmable interface to access Salesforce Metadata Allows you to review/update Metadata components Supported from all modern languages like .Net, Java, PHP Allows you to get/update XML version of an Org SOAP based Supports both Synchronous and Asynchronous invocation Synchronous support added in Summer ’13
Presentation Title Date
Copyright Salesforce 2014. Legal Terms and more here.
Applications of Metadata API Standard Salesforce tools written using Metadata API
Eclipse IDE ANT Migration tool Data loader
Standard configuration on all your customer instances Java screens to create Salesforce objects, fields, validation rules etc Regular backup of configuration
Metadata ComponentsMetadata components Object and Field definitions Visualforce pages Page Layouts Validation rules Apex Workflows Profiles Reports
Presentation Title Date
Copyright Salesforce 2014. Legal Terms and more here.
Metadata API
CRUD Operations File Based (Declarative) Metadata
Use this to create/update Metadata elements like Objects
Use this for deployingMetadata from one Salesforceinstance to another
More Granular Deploy() and Retrieve()
CRUD based web services Used to create, delete, update sets of Metadata components
Create a field Create an object Create a page layout Setting Field Level Security
Synchronous Methods as of v-31 (Summer ’14) createMetadata() deleteMetadata() udpateMetadata() upsertMetadata()
Presentation Title Date
Copyright Salesforce 2014. Legal Terms and more here.
create() flow
AsyncResult object generated. Includes ID
create(new CustomObject(“MyObject”))
Return Async Result
CheckStatus(ID) = done?
Return Deploy Messages
CustomObject co = new CustomObject();co.setFullName(uniqueName);
co.setDeploymentStatus(DeploymentStatus.Deployed);
co.setDescription("Created by Sanchit");co.setEnableActivities(true);co.setLabel(label);co.setPluralLabel(label + "s");co.setSharingModel(SharingModel.ReadWrite);
AsyncResult[] results = metadataConnection.create(new Metadata[] { co });
User
User SFDC
SFDCCustomObject is <xsd: extension
base=“tns:Metadata”>
File based Metadata call File-based Metadata calls
Retrieve and deploy XML representations of Metadata Can be used to deploy Metadata from one instance to another
Requires package.xml Specifies type of component Specifies names of component
Presentation Title Date
Copyright Salesforce 2014. Legal Terms and more here.
{File Name: CustomObject/MyObject__c}<?xml version="1.0" encoding="UTF-8"?><CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">
<deploymentStatus>Deployed</deploymentStatus><fields>
<fullName>Due_Date__c</fullName><defaultValue>TODAY() + 3</defaultValue><label>Due Date</label><type>Date</type>
</fields><sharingModel>ReadWrite</sharingModel><recordTypes>
<fullName>Classification</fullName><active>true</active><description>Classification Records</description><label>Classification</label>
</recordTypes><recordTypes>
<fullName>Client_Code</fullName><active>true</active><description>Client Code Records</description><label>Client Code</label>
</recordTypes></CustomObject>
A typical custom object example
Create Create your
Database Tables
Create Create your
Database Fields
Define Schema
attributes
Metadata API and SOAP API
Metadata
Data
Metadata
Data
Metadata API
Web Services API
Metadata API
Web Services API
Presentation Title Date
Copyright Salesforce 2014. Legal Terms and more here.
Setting up infrastructure
1. Download the latest WSC – Web Service Connector2. From Setup->API
Enterprise WSDLMetadata WSDL
3. Generate the Jar files from WSDL 4. Set the classpath of the Application.
Establishing Connection
1. Use ConnectorConfig class to set end point to https://login.salesforce.com/services/Soap/c/31.02. Use EnterpriseConnection to specify user name and password to login3. Initialize Metadata component – e.g CustomObject, CustomField etc.4. Pass the Metadata component to create() / update() / delete() call.
Presentation Title Date
Copyright Salesforce 2014. Legal Terms and more here.
Best Practices and common issues
Development Scenarios Setting the Page Layout Editing the Profile Creating Record Types
Enforcing rules at runtime involves recompiling of code (with associated possibility of compile time errors).
Presentation Title Date
Copyright Salesforce 2014. Legal Terms and more here.
Profile EditsConfiguring a Profile: Open a profile Edit configurationsNOTE
It’s a complex task to achieve via coding without knowing listMetadata() or Workbench. Default Result of listMetadata() as:
SolutionManagerCustomer Portal Manager Standard StandardAulStandardChatter Free User Chatter External User
Admin Force%2Ecom - Free User MarketingProfileCustom%3A Marketing Profile HighVolumePortal
Record Types CreationGenerally available steps Add a record Type Assign it to layouts and profiles Clicking new on the object viewNOTE
This case is very easily done on declarative platform Doing this via Metadata API is relatively complex
Presentation Title Date
Copyright Salesforce 2014. Legal Terms and more here.
Insufficient Access On Cross Reference Entity An exception Using Create, Update and Delete Occurs using record type id
Demo
Presentation Title Date
Copyright Salesforce 2014. Legal Terms and more here.
A quirk using Ant Migration Tool Using destructiveChanges.xml To delete a field of type picklist we can’t delete the values instead we delete the
whole field. This is the limitation of Metadata API.
Tooling API The tooling API is designed for developing user interface tools to interact with
the development artifacts in orgs. It can be accessed via SOAP and REST. Developer Console is largely built on the tooling API Best used in conjunction with the Metadata API as a junction.
Presentation Title Date
Copyright Salesforce 2014. Legal Terms and more here.
Recap Metadata API gives you flexibility to manipulate Salesforce instance
from outside the platform Two types of Metadata API CRUD based Declarative
Application Business process code needs to mimic the user interface flow Record Type Creations Profile Edits
More important than ever that you define and enforce the boundaries You should respect the intent of platform configurations and not
surface data in ways that is not permitted.
Resources Metadata API Developer’s Guide
http://www.salesforce.com/us/developer/docs/api_meta https://developer.salesforce.com/en/events/webinars/metadata-api salesforce.stackexchange.com https://github.com/sanchitdua/md_java_asynchronous https://github.com/sanchitdua/md_java_synchronous
Presentation Title Date
Copyright Salesforce 2014. Legal Terms and more here.
Q&A