Metadata API

  • Share this:

What is the Metadata? 

Metadata means data about data. Configuration or Code describes how the application looks. It contains business logic. 


What is the Metadata API? 

Programmable interface that allows us to get information about metadata in any programming language like JAVA, .Net, PHP. We can edit,update,create, query information in the XML version of an Org.It supports synchronous and asynchronous invocations and it is SOAP based.



What is the Apex Metadata API ?

In Apex Metadata API you can create, manipulate, update the metadata of salesforce programmatically by using Apex language. 


Features of Apex Metadata API -

1. App providers can build a simple UI which can be used by admins to setup and store their custom metadata information.

2. Admin can easily install apps without support of any professional services


Why is it used?

Apex Metadata API is used for reducing time consuming processes.

For example -

1. Requirement -

Your business needs to create a custom object with their custom fields and perform field level setting in your org and you support more than one org. You have to add this new object and custom fields with their field level settings in multiple Org. Also you have to add the custom fields to the page layout of all orgs and this information is stored in metadata components in your orgs. What can you do?


With the help of Apex language you can create a class in the Metadata namespace.Write a script that uses Apex Metadata API and that will run in all orgs for adding new objects and their custom fields with their layout. You don't have to do manual changes in the multiple org.

2. Requirement -

Your business needs to mark the active to your field usage checkbox in every field of a particular object which already exists in our org. At that time you think to do it by clicking one by one a particular field of an object.



With the help of Apex language you can change the xml file of a particular field and add Active in the xml file which can automatically mark as active to the field usage checkbox of that field after deploy this in our org.


Limitations -

In the new release there are some limitations in metadata API like you can read it, create it,  update it but you can not delete it.


Operations of Metadata API -

 1. CRUD Based Operations - 

 With the help of CRUD operation you can create/update/read metadata elements like objects. But can not delete metadata API. We can control point and click features with the help of CRUD based operation.

 2. File Based Operation -

 With the help of File Based Operation you can deploy metadata from one salesforce  instance to another.We are using deploy() and retrieve() methods to perform operations.It is also known as declarative operations.


Best Practices -

 1. Updating/Editing a Profile -

 If you have an existing profile and you want to change permission sets, field level security then you have access to API names of those profiles. For this you have to call the listMetadata() method. If you don’t call this method then you can not know the API name of those profiles.

 2. Record Type Creation -

Create record type by using record type method in java then assign it to the layout and profile and then click new on the object view.

Vibhuti Rai

Vibhuti Rai

My name is Vibhuti Rai. I am Cloud Apps Engineer at mindZcloud Technologies. I am happy to share new things that I learn. Hope this Blog helps you to enhance your knowledge.