this session is on metadata API some basics of that and then we talked about some special scenarios that that we run into and how to solve those my name is Levine Jobrani I am a CEO of a company astray IT services we are a Salesforce consulting company based in India we have nine apps on app exchange we have got 30 people in India my colleague Sanchez Toa he he he also he is the expert on metadata API so most of the session he’ll be taking ok so the what we’ll be talking today we start with some basic things to set the stage we talked about what is metadata what is metadata API how we can access it what are the type of metadata operations and then we the most of the session today we will be talking about what are the typical scenarios that we run into what are the common problems in metadata API and how do we resolve those what are the best practices in mérida API ok so we all know what is data so it’s your customer information your contact your opportunities all that is the data we are aware of metadata is pretty much pretty much everything else so what is what is displayed what is displayed in a salesforce instance what is the business logic all that is managed through your metadata it is not just the presentation the user interface it is also the business logic that is included in the metadata so as an example pretty much everything that we we talk about in salesforce is considered metadata so your objects your feelings your workflows your reports your approval processes profiles visualforce pages apex everything is metadata when we say metadata we refer to everything now let’s move on to the definition of metadata API what what is it it’s a programmable interface it’s an API that allows us to get information about metadata in algebra programming language flow so let’s say we want to get access we want to search for something’s from Salesforce from Java or.net PHP any modern programming language we can use metadata API to access information to update information we can perform granular information like we can get a particular feeling we can create a new field we can we can also perform a high-level operations like create an XML and deploy an XML to a new instance for we can get an XML which has all the all the field information all the workflows everything in a text and XML format so so those are the kind of two different type of metadata API features that are available this is the soap based API traditionally metadata API was asynchronous so you make a call you do not get the result immediately but in summer 2013 release this has become a synchronous API so you get the results the moment you make a call so so the standard tools that we use Eclipse ID and ant migration tool they are built using metadata API and migration as you know is is a command line tool we’re built on top of ant which allows you to deploy your X and XML file into a new Salesforce instance ok let’s let’s take some business scenarios where mattered metadata API is applicable where it is useful let’s say you’re a consulting company and you want to deploy a similar configuration let’s say you work in healthcare insurance domain so all your many of your customers have similar requirements so what you can do is you can write a Java program that and then and then run it for a new customer so whatever standard you you may have a standard feature set that you implement in all your customer instances so that can be let’s say it will create let’s say a set of custom objects custom fields workflows votes which will force everything you can do it dynamically in a new instance by just writing some Java code you don’t have to manually set it up for every new customer if let’s say all your customers have similar requirements another possible implementation is that let us say you for a specific customer the standard Salesforce user interface to create fields objects is not that applicable that is it’s not that relevant they want a different user interface for for creating reports

creating workflows creating fields so you can build a completely new Java based or dotnet based user interface that will be similar to the standard say it’s possible provide similar functionality but a different user interface the third one is is is another common application is taking backups so so you want to take a backup of your configuration of your code of your fields workflow that sector on a regular basis you can write a Java or.net or PHP program it will it will run every night get the information store it in a store the XML files and you can retrieve it back in at a later date if needed so that’s like some basic introduction about what is metadata metadata API what are the applications we now move on to a bit more technical details and my colleague Sanchez will take over should I can just keep this this presentation is there it’s already loaded these are four slides okay so we are going to talk about some of the differences between the crud pace and pile based metadata API that you can see here is that the crud base is more granular and the file base is deploy and retrieve just just those functions so it the main difference between those is basically we can control all of the point-and-click features using the cred based operations while there is some less control using the metadata file based so moving on to the next thing we have like some of some examples like we can use to create some custom objects fields page layouts or whatever we can think we do in the point-and-click features of the Salesforce so as of version 31 of Salesforce it is supporting synchronous calls before it was a synchronous calls so we have the availability of both of those synchronous as well as asynchronous and the main difference is that we will be getting the results right away using the synchronous calls so these are these methods we make use of some synchronous calls like creating updating visiting Europe or certain so this is the create flow I would like to show you you know guys like this is like we call a create method and we pass the custom object in write on it and then we return the async result so this is the asynchronous workflow you are looking at and we check the status of the results like if it is failed or if it is successful and we get the ID of that as well and we have the access to the deploy messages as well so this is the flow and the right bottom you can see that this is the extension base metadata so we can recognize all of the xml’s which is coming from the metadata and we can recognize those components which are extending those metadata in the tags so this is looked like just creating those objects using the create command and we have some objects and methods while we retrieve those things using the tool that we have available for the metadata operations so moving onto the next slide we have the file based metadata calls which is the XML representation of the Salesforce organization and that can be used for moving the components from one organization to another and it requires a package dot XML file which has the type and the name of the components available so this is just a simple thing and we can make use of it for moving these things so this is just a little introduction about the metadata that we have available like this is the file file base representation of the custom object and we can simply recognize the names of the components using the tags that we have available right now like the fields is the subtype of the custom object which is the parent and this is like just a table of the database and this is the field that we have as an attribute available like we pass the full name and default and label and the type so so we can combine the

metadata along with the soap API to move the components along with the data that we want and this is just an example like we are moving the metadata as well as the data with using this API and we we can use the same organization or the the another organization as a source or the destination so if we just want to get started with this metadata API we have to set up these components and we download the WS C file which is like web service connector available from these Salesforce and we make use of it as a class path for converting the WSDL files that we have into the jar files in the Java and we generate those jar files using this tool and then we just get the access to the class and the patterns that we have for accessing the metadata API so this is just like the endpoint that we have available is soap c31 version like this is just endpoint that we have to make calls for getting access to the metadata API for the organization that we are connecting to so it depends on us we have two types of organizations like sales the sandbox and the the production in case of sandbox we have to use the test dot salesforce.com and in production we have to use login dot salesforce.com and then we have to have the access to enterprise WSDL as well and initialize some metadata components like some classes that we have like custom object custom field and then simply call those methods like create update or delete on them so I would like to discuss some best practices and common issues that we have faced while developing some tool in Java and this is like these are the three scenarios that I am going to discuss and going to give some demonstration as well and this is like creating page layouts or updating them and editing the profiles and what what issues that we face editing the profiles and creating the record types which is again one of the issues if we have to use the crud based metadata API and so this is like if we want to the profiles that we have existing already and we want to make some changes like permission sets and and field level security and things like that then we have to have the access to the API name of those profiles and we can only get those API names for the profile with the help of list metadata call from the WSC that we have otherwise we are facing some trouble inside like we cannot get to know what is the exact name of the profiles so this is just a practice that we have to follow while updating the profiles and again if we are to create the required types that then we have to follow these three steps like we have to add a record type in the record type class available in Java and then we have to assign the layouts and the profiles that we are accessing for those record types so these are the three Munda tree steps that we have to follow and again we have to refresh or update the object that we are in concern for the record types so this is like easily done in point-and-click features like we have simply custom object that we then we create the record types using the new button and then we follow the step by step process but if we are dealing with those things using the programmatic changes then we have to follow these three steps in crud based operations and if we yeah I am just going back to the slides again if we somehow just miss any of those points it is mentioned here as a three step process then we can come to know that this is the exception that we are getting after creating those record types so this is just an exception and it is hard to deal with this such exception that why it is happening and what is happening behind the code so if we face this exception then we have to keep in mind that we are missing something and we have to follow these three steps so I am going to give some demonstration regarding those three practices I would like to correct this machine he can do instance you can log-in insert it like this we have to connect to a different laptop

we can fill in this video we can augment it we have Eclipse okay excuse me let me just call them we have to use a different laptop for the demo yeah we want to use another laptop for the demo we want to use another don’t we have to connect to that with this laptop you want to do this I think yes no no you want to just put this in but what about this nope this one we can be GA we can be touch this as we wouldn’t happen we need a VGA okay can we shift to this mental okay yep so yeah thanks thanks so right here you can see that this is the Eclipse IDE that we are using for developing this Java based application and it is consisting of some classes and some methods that we are making use of some things like using the metadata API for sort so we have a utility class available and you can see that there are lots of methods available here that we can make use of directly for creating the objects fields record types layouts and things like that so if we have to simply create the object and fields right away then we have a let us say this is the hello this is the object this is the origin that we are in concerned with and it does not have any objects right now and you can see that there are no objects so we are creating

the objects right away using this Java programs from from this crash so that we can see if we are to create the objects and fields and then set the layout and then create the required types then how we should do that so this is the application that we have already set and set the infrastructure for this application like we have downloaded the WSDL from the organization that we are in concerned with as well as the enterprise WSDL file along with we have converted them into the jar files that you can see right here highlighting these things like enterprise jar the matador jar and the partner jar so if we have to create the object then this is like a just a call like we have the custom object available and we are passing the name as a full name to it that we have to create this object along with some defaults like what standard name field is going to be like its photo number OS / it’s going to be a text-based so as you can see that this is the part which is in concern like we are creating a text base name field for the standard object for a custom object that is my custom object so if we issue the command of executing this application it should create a custom object named my custom object in the organization so we have simply passed the the username password along with the token that is the sickest token that we have got from the Salesforce organization and then we obtain the session out of it and then calling those classes with the objects so if we refresh this then we can see that a custom object named my custom object 1 is available right now now we create some fields this is the create field class that we have and it should create some fields like the CT contact number the email ID and the last name and we have different types of fields available like we can simply create pick list type fields the text-based fields and we can pass the number of characters that we are allowed for those fields so this is the way so again same thing it is logging into the Salesforce organization and we are getting this session out of it and then we are calling the metadata calls for creating those fields okay so all of those four five fields are created successfully and then we will move forward for updating the layout for the custom object that we are in concern like in this code you can see we are simply updating the layout by calling the utility class that we have and calling the method name update layout so what this code is doing is it is simply making use of the update layout call and we are passing the components and the layout structure as a layout item and we are passing the components that we have to set for those layout items in that layout so this is and I would like to first show that we we don’t have the the layout set for this object and we can see that if we open this custom object and go to the layouts then it is not seen that we have all the fields drop down into a layout so we will create the layout that will drop down all of those fields directly and in a way that we want like we are using the left and the right column based and we

are setting those items into those so after issuing the command of update layout so the layout is upgraded successfully and you can see that some of the fields have been are available over the layout like City contact number email ID and the last name in the left and right directions so what problem that we face in the metadata and we have to follow the best practices we when we create the sorry update the profiles and when we create the record types then this is the thing like I would like to show here is if we update the profile let’s just create a record types first so we have a class name record type available with us and we have to simply pass the name of the record type that we want to set and the API name along with the label name that record type will be sufficing along with the full name that is like containing the dot notation like the object name along with the record type name that we have to set for and there are some attributes of the record types available for us like we have to make it active we have to make it default or we have to set some pick lists for those record types and we have to set those record types for the objects which objects are going to be set so this is just like recreating those record types in a way like we are passing the custom object that we have to be in concern with like this is the custom object that we were and we are simply issuing this method called create record types so what it is doing is it is creating some record types that we have passed in the array and then setting them on the profile as a default or whatever we want like active or inactive and at last we are refreshing the object so I just want to show if we miss any of the step by step process let us say we are not refreshing the object at the end so I am just commenting out this code for letting you know that I am skipping last step that is I am just creating the record types and then setting them to the profile and then just keeping the last step that is refreshing the object so all the way down here is we are using the asynchronous calls that we can make use of this in the synchronous calls as well it is very similar so we are setting the record types for my custom object and we have two record types awesome and the super sorry yes so the status of the record type seems to be completed and we will we would like to review them first so let’s jump on this salesforce organization that we have and if we review the objects that we have that is the my custom object one and we would like to a beauty record types then we can see that these are the two record types available that is the awesome and the super and it seems to be active and we have followed the second step that is we have updated the profile that it is to be set with the visibility of the record types so so we have system administration profile

right now so right now you can see that we have the visibility to be true for those two record types that we have created and now we would like to show you something so it’s all seems to be good we have created the required types we have said there is ability to be true for the organization and now we would like to create some records I should have skipped this point as well so we are just reassigning the record types again and you will see the difference in a minute sure so I am just executing this application again for creating required types and you can see that it will follow the same steps that we had and yes so we have to record types available again and you can see that those two are active and then we will review the profile for the record type settings and it seems to be the same thing and if we just create the records using the tab then it would show there the record types are not showing so the thing is that we have skipped the last step that is updating the or a refreshing the object that is using the update metadata column so that is the thing we have to follow using the required test creation and we also seen that if we are to see update the profiles then we have to use the list metadata call then that is a difference if we have to follow yeah so if we have any questions yeah yes so we will take the questions after the session so thanks thank you