Presentation Title Date Best practices in using Salesforce Meta Data API Naveen Gabrani CEO Astrea IT Services ngabrani At astreait.com @ngabrani Copyright Salesforce 2014. Legal Terms and more here. Sanchit Dua Senior Software Developer Astrea IT Services @Sanchit1 Naveen Gabrani CEO Astrea IT Services ngabrani At astreait.com
Presentation Title Date Copyright Salesforce 2014. Legal Terms and more here. Sanchit Dua Senior Software Developer Astrea IT Services Agenda 1. What is Metadata 2. What is Metadata API 3. How can I access it? 4. Two type of Metadata operations 5. Common applications of the Metadata API 6. Development Scenarios and correct implementation 7. Best Practices and common issues
Presentation Title Date 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 Copyright Salesforce 2014. Legal Terms and more here.
Presentation Title Date 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 Components Metadata components  Object and Field definitions  Visualforce pages  Page Layouts  Validation rules  Apex  Workflows  Profiles  Reports Copyright Salesforce 2014. Legal Terms and more here.
Presentation Title Date Metadata API CRUD Operations File Based (Declarative) Copyright Salesforce 2014. Legal Terms and more here. Metadata Use this to create/update Metadata elements like Objects Use this for deploying Metadata from one Salesforce instance 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 create() flow User SFDC Copyright Salesforce 2014. Legal Terms and more here. 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 SFDC CustomObject 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 A typical custom object example {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> Create your Database Tables Create your Database Fields Copyright Salesforce 2014. Legal Terms and more here. 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 Setting up infrastructure 1. Download the latest WSC – Web Service Connector 2. From Setup->API Enterprise WSDL Metadata 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.0 2. Use EnterpriseConnection to specify user name and password to login 3. Initialize Metadata component – e.g CustomObject, CustomField etc. 4. Pass the Metadata component to create() / update() / delete() call. Copyright Salesforce 2014. Legal Terms and more here.
Presentation Title Date 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). Copyright Salesforce 2014. Legal Terms and more here.
Presentation Title Date Profile Edits Configuring a Profile:  Open a profile  Edit configurations NOTE  It’s a complex task to achieve via coding without knowing listMetadata() or Workbench.  Default Result of listMetadata() as: SolutionManager Customer Portal Manager Standard StandardAul Standard Chatter Free User Chatter External User Copyright Salesforce 2014. Legal Terms and more here. Admin Force%2Ecom - Free User MarketingProfile Custom%3A Marketing Profile HighVolumePortal Record Types Creation Generally available steps  Add a record Type  Assign it to layouts and profiles  Clicking new on the object view NOTE  This case is very easily done on declarative platform  Doing this via Metadata API is relatively complex
Presentation Title Date Insufficient Access On Cross Reference Entity  An exception  Using Create, Update and Delete  Occurs using record type id Copyright Salesforce 2014. Legal Terms and more here. Demo
Presentation Title Date 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. Copyright Salesforce 2014. Legal Terms and more here.
Presentation Title Date 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 Copyright Salesforce 2014. Legal Terms and more here.
Presentation Title Date 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 Copyright Salesforce 2014. Legal Terms and more here. Q&A
Presentation Title Date Copyright Salesforce 2014. Legal Terms and more here.

Best practices in using Salesforce Metadata API

  • 1.
    Presentation Title Date Best practices in using Salesforce Meta Data API Naveen Gabrani CEO Astrea IT Services ngabrani At astreait.com @ngabrani Copyright Salesforce 2014. Legal Terms and more here. Sanchit Dua Senior Software Developer Astrea IT Services @Sanchit1 Naveen Gabrani CEO Astrea IT Services ngabrani At astreait.com
  • 2.
    Presentation Title Date Copyright Salesforce 2014. Legal Terms and more here. Sanchit Dua Senior Software Developer Astrea IT Services Agenda 1. What is Metadata 2. What is Metadata API 3. How can I access it? 4. Two type of Metadata operations 5. Common applications of the Metadata API 6. Development Scenarios and correct implementation 7. Best Practices and common issues
  • 3.
    Presentation Title Date 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 Copyright Salesforce 2014. Legal Terms and more here.
  • 4.
    Presentation Title Date 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 Components Metadata components  Object and Field definitions  Visualforce pages  Page Layouts  Validation rules  Apex  Workflows  Profiles  Reports Copyright Salesforce 2014. Legal Terms and more here.
  • 5.
    Presentation Title Date Metadata API CRUD Operations File Based (Declarative) Copyright Salesforce 2014. Legal Terms and more here. Metadata Use this to create/update Metadata elements like Objects Use this for deploying Metadata from one Salesforce instance 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()
  • 6.
    Presentation Title Date create() flow User SFDC Copyright Salesforce 2014. Legal Terms and more here. 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 SFDC CustomObject 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
  • 7.
    Presentation Title Date A typical custom object example {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> Create your Database Tables Create your Database Fields Copyright Salesforce 2014. Legal Terms and more here. Define Schema attributes Metadata API and SOAP API Metadata Data Metadata Data Metadata API Web Services API Metadata API Web Services API
  • 8.
    Presentation Title Date Setting up infrastructure 1. Download the latest WSC – Web Service Connector 2. From Setup->API Enterprise WSDL Metadata 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.0 2. Use EnterpriseConnection to specify user name and password to login 3. Initialize Metadata component – e.g CustomObject, CustomField etc. 4. Pass the Metadata component to create() / update() / delete() call. Copyright Salesforce 2014. Legal Terms and more here.
  • 9.
    Presentation Title Date 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). Copyright Salesforce 2014. Legal Terms and more here.
  • 10.
    Presentation Title Date Profile Edits Configuring a Profile:  Open a profile  Edit configurations NOTE  It’s a complex task to achieve via coding without knowing listMetadata() or Workbench.  Default Result of listMetadata() as: SolutionManager Customer Portal Manager Standard StandardAul Standard Chatter Free User Chatter External User Copyright Salesforce 2014. Legal Terms and more here. Admin Force%2Ecom - Free User MarketingProfile Custom%3A Marketing Profile HighVolumePortal Record Types Creation Generally available steps  Add a record Type  Assign it to layouts and profiles  Clicking new on the object view NOTE  This case is very easily done on declarative platform  Doing this via Metadata API is relatively complex
  • 11.
    Presentation Title Date Insufficient Access On Cross Reference Entity  An exception  Using Create, Update and Delete  Occurs using record type id Copyright Salesforce 2014. Legal Terms and more here. Demo
  • 12.
    Presentation Title Date 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. Copyright Salesforce 2014. Legal Terms and more here.
  • 13.
    Presentation Title Date 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 Copyright Salesforce 2014. Legal Terms and more here.
  • 14.
    Presentation Title Date 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 Copyright Salesforce 2014. Legal Terms and more here. Q&A
  • 15.
    Presentation Title Date Copyright Salesforce 2014. Legal Terms and more here.