Sub topic 1
Metadata Types and Why a Manifest Is Needed
Prerequisites
This chapter assumes that you know basic Salesforce org concepts, have the Salesforce CLI (sf) installed, and can read simple XML. You should also have an authorized sandbox or scratch org and a Salesforce DX project with a force-app directory.
Metadata Types and Why a Manifest Is Needed
Salesforce metadata describes the configuration and code in an org. Examples include Apex classes, custom objects, custom fields, permission sets, and Lightning components. Each category is a metadata type with its own naming rules.
A manifest is an XML file that tells the Metadata API which components to retrieve or deploy. The standard manifest file is named package.xml. It does not contain the component source. It contains the metadata types, member names, and API version that define the operation's scope.
Anatomy of `package.xml`
The types element groups members by metadata type. The name element identifies the type, and version selects the Metadata API version.
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>AccountService</members>
<members>AccountServiceTest</members>
<name>ApexClass</name>
</types>
<types>
<members>Account.Region__c</members>
<name>CustomField</name>
</types>
<version>62.0</version>
</Package>Naming Members Correctly
Member names must match the Metadata API's format. A custom field combines its object and field API names with a period, such as Account.Region__c. An Apex class uses only its class name.
Foldered metadata commonly uses a path-like name, such as Sales Reports/QuarterlyRevenue. Check the metadata type's naming rules before creating a manifest.
A wildcard selects every member of a type:
<types>
<members>*</members>
<name>ApexClass</name>
</types>Use wildcards carefully. They can retrieve or deploy more components than intended, and they are not supported in destructive changes files.
Generating a Manifest
Generate a manifest from source with:
sf project generate manifest \
--source-dir force-app \
--name manifest/package.xmlYou can also generate one from named metadata components:
sf project generate manifest \
--metadata ApexClass:AccountService \
--metadata CustomObject:Account \
--name manifest/package.xmlThe generated file is still XML, so review its members and API version before using it.
Exercise
In a package.xml file, which element identifies a metadata category such as Apex classes?
Show answer
The <name> element inside a <types> element, such as <name>ApexClass</name>.