Skip to main content

Salesforce Custom Metadata - creation and migration



In my last post, i tried to explain a use case for custom metadata and talked about its advantages -
Salesforce Custom Metadata - Usage and Advantages. As promised in this post, i am going to walk you through an example of what I built for this particular custom metadata type.

The use case for this example is detailed in the earlier post.


  • To create a custom metadata, go to Setup -> Develop -> Custom Metadata Types.
  • Click New Custom Metadata Type button and populate the Label details. 
  • Also there is a setting "Visibility" that controls if only a managed package can use this metadata type or any Apex code can use it. I set it to an Apex code based on my use case.
Below is the new metadata type i created -

  • On drilling into the new metadata type, you can define what all fields are required to hold the metadata information. I configured two custom fields to capture the queue name and the cutoff time fields. So every record in this metadata type will have these two fields populated.

  • Now to add actual metadata records, click the Manage SLA Cutoff Settings button. Here I can click New and add a new record which captures the Queue name and the cutoff time in it for 1 queue -

  • Similarly I can add as many records as I need. Remember these are metadata records you are adding for the new metadata type you created earlier. So these are available to the Metadata API, change sets, ANT based Force migration tool etc.
  • Now that we have setup the configuration records that we can use in your logic, the next logical step is to see how exactly can i use it. Consider you want to use it in an Apex class or trigger, you can do this by using a simple SOQL statement. See below soql that i can use to pull the cutoff time for a particular queue -

  • Now lets talk about migration. Remember this is the biggest advantage of having this configuration data as a custom metadata type. Lets say i want to migrate all this queue cutoff information from one sandbox to the next, I can do so using ANT based force migration tool alone. No need for data loader or manual data creation. Below I will show how we can use ANT to retrieve this metadata we just created.
  • First let me put together a simple package.xml that can be used to retrieve all custom metadata types - 

  • Now in the build.xml that will be used by ANT, below target is configured to retrieve the metadata specified by above package.xml -

  • Now let me execute the ANT command and then we can check what is retrieved - 

  • Lets examine what got retrieved, to confirm it is not just the definition of the SLA Cutoff Time metadata type but also the actual metadata records we created earlier to capture the queue to cutoff time configuration information.



There you go, the retrieved metadata has the actual data values we created in the UI. Thus when we deploy this to the next environment, these records are automatically added. So now we need not worry about getting the data records migrated separately!

Hope this was informative and useful!

Comments

Popular posts from this blog

Workaround to bypass Salesforce SSO

One of the best practices for implementing Single Sign On for your Salesforce org is always ensure there is a way your System administrator can login via the standard login page side-stepping the SSO configuration.  Reason for this is if ever something goes wrong with your Idp provider's service and the SSO authentication responses are not coming as expected, all your users are unable to login. That is, if you have setup your My domain to prevent logins via standard Salesforce login urls (login.salesforce.com). This includes the System administrator as well. Only if your system administrator can somehow login, then he or she can disable the SSO settings for your domain and allow login via the normal login page as a temporary measure. What do you do in such a situation? Well Salesforce has built a workaround for this which is not well documented anywhere (probably for a good reason :) ). I found out about it from a colleague at work. If your my domain url is - https://Com

Salesforce Big Objects - Key learnings

I remember reading about Salesforce Big Objects before they became available and thought maybe it is an option to backup data present in regular objects. That is, instead of taking a backup via an ETL tool or data loader, maybe this will be an option to backup the data in the Force.com platform itself. Now that it is GA and I am reading more about it, i think the use cases for this are more varied. Some use cases I can think of are –  Archival of key data objects within the platform: You may want to use this option if you dont use any other means to backup key data. Also this may be an attractive option for non-large enterprise customers who dont themselves invest on large data warehouses or data lakes in their enterprise architecture. Ex: customer history (if present in tasks and activities) will become huge over years but this is useful information for reporting & customer analysis. Store key information which is large volume in quantity and also high volume in transa

DBAmp for Salesforce - salesforce integration for SQL Server DBAs

Recently i got the opportunity to explore a tool called DBAmp for integration with Salesforce. I found it to be a very useful tool which will help with any data manipulation requirements in Salesforce. Following are my learnings from the exercise. Hope it helps any of you who may need to work with this tool -  DBAmp is a SQL Server package that can be used to integrate with Salesforce. The site where this software is available is - http://www.forceamp.com/ Overview: It essentially installs on top of an existing SQL Server database and provides an OLE DB connector that can be used to connect to Salesforce. Behind the scenes, it executes API calls against Salesforce for any SQL server command it receives. Thus we can create a connection in SQL server to Salesforce org and pull data into tables in the database just as if we are querying against Salesforce tables directly. Use cases for DBAmap + Salesforce: Many use cases exist for using this tool against Salesforce. Pr