Sub topic 1
Metadata Types and Components
Every Salesforce customization is metadata. This chapter defines the two words you will see in every later chapter: metadata type and component. The rest of the tutorial builds on them.
Prerequisites
This chapter assumes you have:
- Basic familiarity with Salesforce metadata such as Apex classes, custom objects, and custom fields.
- Comfort reading XML and navigating a project directory.
- Basic command-line and Git usage.
You do not need a Salesforce org or the CLI installed yet to follow this chapter.
What metadata is
Metadata is data that describes how your org is configured and how it behaves. Records such as an Account named "Acme" are data. The Account object definition, its fields, its page layouts, and the Apex code that runs on it are metadata.
The Metadata API is the programmatic interface that reads and writes this configuration. The Salesforce CLI uses it to retrieve metadata from an org and deploy metadata to an org.
Types and components
A metadata type is a category of configuration. A metadata component is one concrete instance of a type.
| Metadata type | Example component |
|---|---|
| ApexClass | MyClass |
| ApexTrigger | AccountTrigger |
| CustomObject | Account, Invoice__c |
| CustomField | Account.Rating_Notes__c |
| Layout | Account-Account Layout |
| Profile | Admin |
So ApexClass is the type, and MyClass is a component of that type. A component has a name, called its full name. Standard objects use a plain name such as Account. Custom components usually end with a suffix such as __c. Some components belong to a parent, so their full name includes the parent, written with a dot, as in Account.Rating_Notes__c.
Why the distinction matters
Tools that move metadata always need two answers: which types, and which components of those types. A manifest file named package.xml gives those answers. It lists types, and under each type it lists member names. A member is the name of one component.
Here is a small manifest that selects two components:
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>MyClass</members>
<name>ApexClass</name>
</types>
<types>
<members>Account</members>
<name>CustomObject</name>
</types>
<version>60.0</version>
</Package>Read it from the inside out. The name element holds the type. Each members element holds a component name of that type. The version element sets the API version used for the retrieve or deploy. Later chapters cover the manifest in detail.
One component, different files
A component is a logical unit. Its files on disk depend on the layout you use. In Metadata API format, one component is usually one file. In source format, a large component such as a custom object can be split into many files.
The type and component stay the same in both layouts. Only the arrangement of files changes. Keeping this in mind makes the two formats much easier to compare.
Common mistakes
- Treating a type as a component.
ApexClassin a manifest means the type. UseMyClassas the member, or use*to select every component of the type. - Assuming one component means one file. This holds in Metadata API format but often fails in source format.
- Assuming every component lives under its own type name. A custom field is a component of type
CustomField, but its file sits under its parent object's folder in source format.
Exercise
In the manifest entry with <members>Account</members> and <name>CustomObject</name>, which part is the metadata type and which part is the component?
Show answer
CustomObject is the metadata type, given by the name element. Account is the component, given by a members element.
Exercise
The full name Account.Rating_Notes__c identifies a component. What is its type, and what does the part before the dot represent?
Show answer
Its type is CustomField. The part before the dot, Account, is the parent object that the field belongs to.