Sub topic 1
Metadata Types and Components
Prerequisites
You should know basic Salesforce metadata, including Apex classes, custom objects, and custom fields. You should also be comfortable reading XML and using directories, Git, and a command line.
Metadata Types and Components
A metadata type describes a kind of Salesforce configuration. Examples include ApexClass, CustomObject, and CustomField. A component is one item within a type. For example, MyClass is an Apex class component, and Account is a custom object component.
Salesforce stores these components on disk in two layouts. Metadata API format is designed around API retrieve and deploy operations. Source format is designed for Salesforce DX projects and version control.
Metadata API Format
Metadata API format usually stores one file for each component. Files are grouped into folders by type. A custom object can be represented by one Account.object file containing the object and its fields.
A deployment or retrieval commonly uses a package.xml manifest. The manifest selects the metadata types and component members to include.
<?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>The version element sets the Metadata API version. A wildcard member, such as *, selects every component of a type.
Source Format
Source format decomposes metadata into smaller files. It places project source under a package directory, commonly force-app/main/default.
force-app/main/default/
classes/
MyClass.cls
MyClass.cls-meta.xml
objects/
Account/
Account.object-meta.xml
fields/
Rating_Notes__c.field-meta.xmlThe same custom object that was one .object file in Metadata API format becomes a folder in source format. Each field gets its own file. This decomposition makes Git diffs smaller and helps developers review one change at a time.
A -meta.xml file contains metadata about a source component, such as its API version or visibility. It is a companion file, not a separate Salesforce component. Apex classes, triggers, and many other source files require one.
Exercise
Which format normally gives a custom field its own file?
Show answer
Source format. It stores the field in the object's fields directory.