WEBINAR : Becoming a Salesforce Release Automation Superstar.  Register now

+1 925 500 1004


4 Ways to Fetch Metadata in Salesforce

Metadata can be used in a variety of ways because it essentially identifies characteristics of other data sets.

Organizing this data, arranging relationships between sets of data, and customizing unique characteristics of your Salesforce instance are all made possible through metadata.

meeting around computers_AutoRABITFinding and extracting data is fairly easy. It’s in the forefront. It’s easily copied, dragged, and moved between organized folders. But what about metadata?

Metadata often lurks behind the scenes. It’s even a bit mysterious to those that don’t directly work with it. However, metadata is important. It can be backed up to retain customizations to your Salesforce platform in the event of a disaster, it is an essential aspect of a useful data governance plan, and more.

Locating and retrieving your Salesforce metadata can be a little difficult, but it’s possible with some intentional considerations.

So how do you do this? It often depends on what you plan to do with the metadata after locating it.

Here are 4 methods of retrieving your Salesforce metadata.

  1. API
  2. ANT Migration Tool
  3. Managed Package
  4. Manually Search Objects

1. API

An Application Programming Interface (API) is “a way to programmatically interact with a separate software component or resource.

Essentially, it’s a way to organize the code you write and make the functions repeatable.

And just how APIs can be used to organize code, they can also be used to retrieve and organize your metadata.

Metadata API in Salesforce can be used “to retrieve, deploy, create, update or delete customization information.” This is commonly used to move changes made in a sandbox—or another test org—into your active production environment.

One of the most useful ways to leverage metadata in Salesforce is to customize the platform. Metadata API can be used to manage these customizations as well as other tools to help manage your overall model for metadata.

There are multiple ways to utilize Metadata API in Salesforce. One of the easiest ways to do this is to use the ANT Migration Tool—this is done using the command line to move the metadata between an org and a local directory.

2. ANT Migration Tool

Some simple commands can be used with the ANT Migration Tool to move metadata out of a Salesforce org and into a local filing system. This is useful if you need to:

  • Move a customization or custom application after development and testing is completed
  • Distribute the application after team development

The ANT Migration Tool is a command-line tool that can be used to move metadata.

This tool is beneficial when:

  • Repetitive deployments are needed, using the same parameters
  • Release processes are performed through multiple stages
  • A test environment is being used to examine setup changes
  • Batch deployments are scheduled

ML files contain metadata and can be retrieved by utilizing the deploy () and retrieve () calls. Retrieving the XML files will then allow you to move them into local files where developers can manage changes, copy and/or paste setup configurations, institute component changes, or otherwise develop the files.

These changes can be deployed to other Salesforce orgs at any time.

Using the ANT Migration Tool to move metadata with the deploy () and retrieve () calls provides a seamless interaction with the API. This makes the process much smoother for developers when compared to writing the calls directly into their lines of code.

3. Managed Package

Managed Packages are pre-built collections of application components constructed either in-house, or by an independent software vendor (ISV).

Creating a Managed Package in Salesforce is fairly easy. The only requirement is that you possess the developer version of Salesforce. And once you have this package, you can send and retrieve the metadata as you need.

The first step is to simply create a folder to store the information you are going to pull out from your Managed Package. Retrieve the metadata from the package using this code:

sfdx force:mdapi:retrieve -s -r ./mdapipkg -u <username> -p <package name>

Check the status of the retrieve by running:


The target username, job ID, and retrieve directory will all be stored when this is run. This saves you the time of specifying parameters to check the status of the retrieve. Keep in mind that these values will all be replaced if you run the code again.

However, you can manually enter the job ID and retrieve directory in the operation line if you’d like to check the status of a different retrieve operation.

After that, all you need to do is unzip the zip file and save it in the proper location.

4. Manually Search Objects

Even comprehensive migrations can occasionally leave behind customizations or intentional functionality. This can either be rectified through manual re-programming to return your system to the previous state, or you can attempt to dig up the metadata.

Using a mouse and computer_AutoRABIT

The SOAP API Developer Guide is a great source for the available objects, their fields and purposes, and operations. There are a variety of tools which includes diagrams of your objects and relationships within the platform services.

This includes Salesforce Knowledge Objects, Content Objects, and Sales Objects.

Seek out the section of available information relating to any holes in your current pool of metadata and related objects. Dig into them and compare them against your list of supported metadata in the API.

Gather the objects in an package.xml file and perform a retrieve from this new repository of information.

Metadata exists in every section of your Salesforce platform. The ubiquity of metadata makes it difficult to find and extract every piece, so you will need to utilize numerous tactics to have the best chance at creating a comprehensive snapshot.

Share on twitter
Share on linkedin


The Automation Effect Streamlining DevSecOps in 2021