Registration is open for AutoRABIT's annual conference Dev(H)Ops Live April 10-11 2024: Save your spot

+1 925 500 1004

+1 925 500 1004

Blog Circle icon

4 Ways to Fetch Metadata in Salesforce

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.

deploy metadata records salesforceFinding 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. A Salesforce metadata backup will ensure that you 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. Metadata API
  2. ANT Migration Tool
  3. Managed Package
  4. Manually Search Objects

1. Salesforce Metadata 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 various Salesforce metadata types.

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. A Salesforce 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 a Salesforce org and a local directory.

2. ANT Migration Tool

Some simple commands can be used with the ANT Migration Tool to move Salesforce 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

metadata in salesforceML 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 Salesforce Metadata 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.

metadata api salesforce

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 Salesforce org 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 for your Salesforce metadata search.


Metadata is often described as “data about data,” but it’s so much more than that. It describes the files themselves but it can also be used to create dependencies and other functions within Salesforce.

An Application Programming Interface (API) is a way to organize the code you write and make the functions repeatable.

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