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, and have a Salesforce DX project with the Salesforce CLI (sf) authorized to a sandbox. Here you learn how to write the text inside each <members> element.
Why member names matter
The Metadata API matches each member against a component in the org by exact name. A name that doesn't match is not guessed at. In a retrieve, the component is skipped with a warning. In a deployment that deletes, the file fails or deletes nothing. Naming errors cause many of the deletion problems later in this tutorial.
There are three naming shapes:
| Shape | Used for | Example |
|---|---|---|
| Name only | Top-level components | `AccountService` |
| `Parent.Name` | Components that belong to an object | `Account.Region__c` |
| `Folder/Name` | Components stored in folders | `SalesReports/QuarterlyPipeline` |
Top-level components
Apex classes, Apex triggers, Lightning components, flows, and custom objects are top-level. Use the API name with no extension and no folder path. Write AccountService, not AccountService.cls. A custom object keeps its suffix: Invoice__c.
Components that belong to an object
Custom fields, validation rules, record types, list views, compact layouts, and buttons and links are children of an object. Prefix the component name with the object API name and a dot.
<?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>
<types>
<members>Account</members>
<members>Invoice__c</members>
<name>CustomObject</name>
</types>
<version>62.0</version>
</Package>Three details cause most mistakes:
- Keep the
__csuffix on custom fields and custom objects.Account.Regiondoes not matchAccount.Region__c. - Standard objects use their plain name, such as
Account. Custom fields on a standard object still appear asAccount.Region__c. - The
<name>value is the metadata type, not the object. A field belongs underCustomField, even though it lives insideCustomObjectin your source folder.
Components stored in folders
Reports, dashboards, documents, and email templates live in folders. Their members are written FolderName/ComponentName. The folder itself is a member of the same type, written as just the folder name.
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>SalesReports</members>
<members>SalesReports/QuarterlyPipeline</members>
<members>unfiled$public/OpenCases</members>
<name>Report</name>
</types>
<version>62.0</version>
</Package>Reports in the shared unfiled folder use unfiled$public. If you list only a report and its folder doesn't exist in the target org, the deployment fails. Include the folder member, or make sure the folder is already there.
Wildcards
A * member selects every component of that type. It works in retrieve and deploy manifests:
<?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>Keep these limits in mind:
*is not supported in destructive changes files. Name each component to delete.*underCustomObjectreturns custom objects only. Name standard objects such asAccountexplicitly.- For folder-based types, don't rely on
*to pick up the contents of folders. List folders and their components by name. - A wildcard in a deployment manifest only covers components that exist in your local source. It does not mean "everything in the org".
Common naming errors
- Adding a file extension, such as
AccountService.cls. - Leaving off the object prefix, or the
__csuffix. - Using the wrong
<name>type, such asCustomObjectfor a field. - Using a space or line break inside a member. Keep each name on one line.
- Using a wildcard in a destructive changes file.
Exercise
You want to delete the custom field Region__c from the Account object. Write the type name and member name you would put in a destructive changes file, and say whether * could replace the member.
Show answer
Use <name>CustomField</name> with <members>Account.Region__c</members>. A wildcard can't replace the member, because destructive changes files don't support *. Each component to delete must be named exactly.