Sub topic 3
Naming members correctly: fields, folders, and wildcards
This chapter assumes you can read a basic package.xml, know the types, members, name, and version elements from the previous chapter, and have a Salesforce DX project with a sandbox authorized in the sf CLI. It covers how to write the members value for each kind of component. A wrong name is the most common reason a retrieve returns nothing or a deletion fails.
Why naming matters
The Metadata API matches each members value against the full name of a component. It does not guess or fuzzy match. If the name is wrong, one of two things happens:
- A retrieve or deploy reports a warning that the entity was not found, or silently returns fewer components than you expected.
- A destructive deployment fails, or deletes nothing, because the name matches no component in the org.
Names are also case-sensitive in practice. Copy them from the org or from your source files instead of typing them from memory.
Three naming shapes
Almost every member name follows one of three shapes. The shape depends on where the component lives.
| Shape | Used by | Example member | Metadata type name |
|---|---|---|---|
| Plain name | Top-level components | `AccountService` | `ApexClass` |
| `Parent.Child` | Components that belong to an object | `Account.Region__c` | `CustomField` |
| `Folder/Item` | Components stored in folders | `SalesReports/Pipeline` | `Report` |
Top-level components: plain names
Apex classes, Apex triggers, Lightning web components, flows, and custom objects are top-level components. The member is the API name with no file extension, no folder path, and no -meta.xml suffix.
<?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>Invoice__c</members>
<name>CustomObject</name>
</types>
<version>62.0</version>
</Package>Two details trip people up here.
- Source file names are not member names. The file
AccountService.clsis the memberAccountService. The fileInvoice__c.object-meta.xmlis the memberInvoice__c. - Namespaces are part of the name. A component from a managed package is written with its prefix, such as
acme__Invoice__c. In an unlocked or unmanaged project with no namespace, leave the prefix off.
Child components: Object.Name
Some components cannot exist without a parent object. Their member name is the object API name, a period, and the component API name. Common examples:
| Metadata type | Example member |
|---|---|
| `CustomField` | `Account.Region__c` |
| `ValidationRule` | `Account.RequireRegion` |
| `RecordType` | `Case.Support` |
| `ListView` | `Lead.AllOpenLeads` |
| `CompactLayout` | `Contact.Mobile_Layout` |
| `FieldSet` | `Account.Summary_Fields` |
| `WebLink` | `Opportunity.Send_Quote` |
| `BusinessProcess` | `Opportunity.Standard_Sales` |
Standard objects use their plain API name (Account, Contact). Custom objects use the name with __c. A custom field on a custom object looks like Invoice__c.Amount__c.
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>Account.Region__c</members>
<members>Invoice__c.Amount__c</members>
<name>CustomField</name>
</types>
<types>
<members>Account.RequireRegion</members>
<name>ValidationRule</name>
</types>
<version>62.0</version>
</Package>On disk, fields live in objects/Account/fields/Region__c.field-meta.xml. The folder names give you the two halves of the member: Account from the object folder and Region__c from the file name.
Fields inside CustomObject
A CustomObject member can also carry its fields. If you retrieve Invoice__c as a CustomObject, the result includes the object's fields, validation rules, and other children. If you list Invoice__c.Amount__c as a CustomField, you get only that field. Choose the narrower form when you want a small, reviewable deploy.
For a destructive changes file, the narrow form is the one you want. Listing Account.OldRegion__c under CustomField deletes one field. Listing Account under CustomObject in a destructive file would try to delete the whole object, which for a standard object is not allowed.
Layouts and special characters
Page layouts are named ObjectName-LayoutName, with a hyphen, as in Account-Account Layout. If the layout name contains special characters, they are percent-encoded. A layout called Account (Marketing) Layout is written Account-Account %28Marketing%29 Layout. If a layout member fails to match, compare it with the name that sf org list metadata prints for that layout.
Folder-based components
Reports, dashboards, documents, and email templates are stored in folders. The member is the folder name, a forward slash, and the item name.
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>SalesReports</members>
<members>SalesReports/Pipeline</members>
<members>SalesReports/Pipeline_By_Region</members>
<name>Report</name>
</types>
<types>
<members>SalesEmail/Welcome_Template</members>
<name>EmailTemplate</name>
</types>
<version>62.0</version>
</Package>Notice that the folder itself, SalesReports, is also a member. It sits under the same type name as the items it holds (Report, not a separate folder type). If you deploy a report into a folder that does not exist in the target org and you do not include the folder, the deployment fails. Include the folder as a member when it may be missing.
Nested folders extend the path with more slashes: SalesReports/EMEA/Pipeline. Each level of folder needs to exist before the item inside it.
Two other points about folders:
- Folder names are API names, not labels. The label shown in the Reports tab can differ from the name used in the manifest. The
DeveloperNameof the folder is what counts. - Standard unfiled folders have fixed names. Reports saved to "Unfiled Public Reports" use the folder name
unfiled$public. Written as a member, that isunfiled$public/MyReport.
Wildcards
A member of * means "every component of this type".
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>*</members>
<name>ApexClass</name>
</types>
<version>62.0</version>
</Package>Wildcards are convenient for retrieves and for broad deployments, but they have limits that you should know before relying on them.
- They are not allowed in destructive changes files. Destructive files must list each component by its exact name. This is a safety feature, because a wildcard delete would be very hard to undo.
- They do not cover every type. Some types do not support
*. Check the Metadata Coverage report or the Metadata API reference entry for the type. - Standard objects are excluded from
CustomObjectwildcards.*underCustomObjectreturns custom objects only. To includeAccountorContact, list them by name alongside the wildcard. - Folder contents need explicit names. A wildcard under a folder-based type such as
Reportdoes not reliably return the reports inside folders. List each folder and report instead, as shown above. - A wildcard retrieves what exists now. If a colleague adds a class to the org, your next retrieve picks it up. That is useful for backups and risky for repeatable deployments.
You can mix a wildcard with named members in the same types block. For example, * plus Account under CustomObject retrieves every custom object and the standard Account object.
Partial wildcards on the command line
The --metadata flag of sf project retrieve start and sf project deploy start accepts a type, a colon, and a name, so you can skip the manifest for quick jobs. It also accepts a trailing * as a prefix match:
sf project retrieve start \
--metadata "ApexClass:Account*" \
--metadata "CustomField:Account.Region__c" \
--target-org my-sandboxThis is a CLI feature and not part of the package.xml format. A package.xml file supports only a bare *, and Account* inside a manifest is treated as a literal name that matches nothing.
Finding the exact name
When you are unsure of a name, ask the org instead of guessing.
sf org list metadata \
--metadata-type CustomField \
--target-org my-sandboxFor folder-based types, add the folder:
sf org list metadata \
--metadata-type Report \
--folder SalesReports \
--target-org my-sandboxThe output includes a fullName for each component. That fullName is the string to use as the member. If the type itself is in doubt, sf org list metadata-types --target-org my-sandbox prints the type names the org supports, which are the strings that go in the name element.
Common naming errors
| Symptom | Likely cause | Fix |
|---|---|---|
| Retrieve returns no field | Member written as `Region__c` without the object | Use `Account.Region__c` |
| Warning that an entity was not found | Typo, wrong case, or missing `__c` | Copy the `fullName` from `sf org list metadata` |
| Report deploy fails with a missing folder | Folder not included or not yet in the target org | Add the folder as a member |
| Destructive deploy changes nothing | Name does not match, or a wildcard was used | List the exact `fullName` |
| Layout is not found | Special characters not encoded | Percent-encode them, such as `%28` and `%29` |
| `*` returns no standard objects | Wildcard covers custom objects only | Name standard objects explicitly |
| Component from a managed package missing | Namespace prefix left out | Include the prefix, such as `acme__Invoice__c` |
Putting it together
Suppose you need to retrieve an Apex class, one custom field, and a report with its folder. The manifest below uses all three naming shapes. The wildcard is limited to a type where it is safe to use.
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>AccountService</members>
<name>ApexClass</name>
</types>
<types>
<members>Account.Region__c</members>
<name>CustomField</name>
</types>
<types>
<members>SalesReports</members>
<members>SalesReports/Pipeline</members>
<name>Report</name>
</types>
<version>62.0</version>
</Package>When you retrieve with this manifest, check the project afterwards. You should see AccountService.cls, objects/Account/fields/Region__c.field-meta.xml, and the report under reports/SalesReports/. A missing file points you to the member that did not match.
Exercise
You want a destructive changes file that deletes the custom field OldRegion__c on the standard object Account and the Apex class LegacyAccountService. Write the two types blocks, and say whether you could shorten the class entry with *.
Show answer
The blocks are <types><members>LegacyAccountService</members><name>ApexClass</name></types> and <types><members>Account.OldRegion__c</members><name>CustomField</name></types>. You cannot use *. Destructive changes files do not support wildcards, so each component must be listed by its exact name. The field needs the Account. prefix because it is a child of an object.
Exercise
A report named Pipeline sits in the folder SalesReports. You deploy it to a new sandbox and the deployment fails. The manifest lists only SalesReports/Pipeline under Report. What is the most likely problem, and how do you fix it?
Show answer
The folder SalesReports does not exist in the target org, and the manifest does not include it. Add <members>SalesReports</members> under the same Report type, together with the folder's metadata in your source, so the folder is created before the report.
Exercise
Which command prints the exact names to use as members for all custom fields in a sandbox called my-sandbox?
Show answer
sf org list metadata --metadata-type CustomField --target-org my-sandbox. The fullName in each result, such as Account.Region__c, is the string to use as the member.