Sub topic 1
Configuration is metadata, not data
Prerequisites
This chapter assumes you have:
- Basic Salesforce administration skills in Setup.
- An understanding of the difference between a production org and a sandbox.
- Familiarity with metadata types such as custom objects, fields, flows and Apex classes.
- Optionally, a user with the Deploy Change Sets permission and access to a sandbox, if you want to follow along in an org.
Two kinds of things in an org
A Salesforce org holds two kinds of content. Change sets move only one of them.
- Metadata describes how the org is built. Examples are a custom object definition, a field, a validation rule, a flow, a page layout and an Apex class.
- Data is the records users create inside that structure. Examples are Accounts, Opportunities and rows in an
Invoice__cobject.
Suppose you add an Invoice__c object and an InvoiceService Apex class in a sandbox. A change set can carry the object definition and the class to production. It cannot carry the invoice records you created while testing.
Why the split matters
The split affects how you plan a release.
- Test data stays in the sandbox. Production gets the structure but not your sample records. An empty new object in production is expected.
- Reference data needs another route. If your configuration depends on records, such as a price book, you load them in the target org yourself. You can use Data Loader, the Data Import Wizard or a script.
- Some configuration blurs the line. Custom metadata type records count as metadata, so a change set can carry them. Custom settings are different. A change set carries the definition of a custom setting but not the values stored in it.
- Settings and records can reference each other. A flow might look up a record by name. The flow deploys, but the record it expects might not exist in production, and the flow fails there at run time.
Seeing metadata as a list
Every component is identified by a metadata type and a name. A package.xml manifest lists components in that form. A change set holds the same kind of list.
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>Invoice__c</members>
<name>CustomObject</name>
</types>
<types>
<members>InvoiceService</members>
<members>InvoiceServiceTest</members>
<name>ApexClass</name>
</types>
<version>61.0</version>
</Package>The manifest names one custom object and two Apex classes. It contains no records, only the names of components.
You can use the Salesforce CLI to retrieve those components from a sandbox. The files you get back show what a change set would contain.
sf project retrieve start --manifest manifest/package.xml --target-org MySandboxCommon mistakes
- Expecting records to arrive. After a deployment, the new object exists in production but has no rows. This is correct behavior, not a failed deployment.
- Assuming a setting's values travel with its definition. Check each custom setting in the target org after deployment.
- Forgetting that the target org needs the data a flow or class depends on. Plan to load that data before users rely on the feature.
Exercise
You add a custom field, a validation rule and 200 test Account records in a sandbox, then deploy a change set to production. Which of these arrive in production, and how would you get the rest there?
Show answer
The custom field and the validation rule arrive, because they are metadata. The 200 Account records do not, because they are data. If you need them in production, load them separately with Data Loader or the Data Import Wizard. Test records usually should not go to production at all.