Sub topic 1
Configuration is metadata, not data
This chapter sets up the idea that every later chapter depends on. A change set moves metadata between Salesforce orgs. It never moves data. If you keep that line clear, most deployment surprises become predictable.
Prerequisites
This chapter assumes you already have the following:
- 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.
- For hands-on practice later in the tutorial, a user with the Deploy Change Sets permission and access to a sandbox and its production org.
You do not need to write code to follow this chapter. The two code examples are short and are there to show how metadata is described and retrieved.
Two kinds of things live in an org
A Salesforce org holds two broad categories of content.
- Data is the records your users create and update. Examples are accounts, contacts, opportunities, cases, and the invoices a team enters each day.
- Metadata is the definition of how the org is built and how it behaves. Examples are the custom object that describes an invoice, the fields on it, a validation rule, a flow, a page layout, or an Apex class.
A useful test is to ask whether the item describes the structure or is an entry stored in that structure. The Invoice__c object is metadata. A single invoice named INV-0042 is data.
| Item | Category | Moves in a change set? |
|---|---|---|
| Custom object `Invoice__c` | Metadata | Yes |
| Custom field `Invoice__c.Amount__c` | Metadata | Yes |
| Apex class `InvoiceService` | Metadata | Yes |
| Flow that sets an invoice status | Metadata | Yes |
| Page layout for invoices | Metadata | Yes |
| The record `INV-0042` | Data | No |
| A contact record | Data | No |
| A user's password | Data (user and security information) | No |
Why Salesforce separates them
Salesforce is a multitenant platform. Your org's behavior is stored as metadata, so the platform can describe, copy and replace that behavior without touching the records. This separation is what makes a sandbox useful. You can build and test a change against a copy of the structure, then apply the same structure to production.
The separation also protects production. A sandbox may contain test records, scrambled or masked data, or half-finished experiments. If a change set carried records, those would overwrite or pollute real business data. Because it carries only definitions, production keeps its own records after a deployment.
What this means in practice
Three consequences follow, and each shows up again later in the tutorial.
- Structure arrives empty. If you deploy
Invoice__cto production, production gets the object and its fields. It does not get any invoice records from the sandbox. The object starts with zero records unless you load data some other way. - Some configuration is stored as data. A few kinds of setup are records, not metadata, so a change set cannot carry them. Treat this as a check you make for each item, not as a rule you can assume. Typical examples of content you may need to recreate or load by another method include records in custom objects used as lookup tables, and some settings values. Later chapters on limitations and manual steps cover what to do about them.
- Dependencies are about metadata. A flow that refers to a field needs that field to exist in the target org. Dependencies are relationships between metadata components, not between records.
<br>
How metadata is described
Salesforce describes metadata in XML. The same description is used by change sets, the Metadata API, and developer tools. A manifest file called package.xml lists components by type and name. A change set holds the same kind of list, which you build through the Setup interface instead of by editing XML.
<?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>Read it in three parts.
- Each
typesblock groups components of one metadata type. Thenameelement holds the type, such asCustomObjectorApexClass. - Each
memberselement holds the API name of one component. - The
versionelement is the API version used to interpret the definitions.
Nothing in this file names a record. There is no place in the format to list an invoice, a contact or an account. The manifest can only point at definitions.
Looking at metadata yourself
You can see exactly what the metadata of an org looks like by retrieving it. The Salesforce CLI command below retrieves the components named in the manifest from a sandbox. The sandbox is identified by its alias, MySandbox.
sf project retrieve start --manifest manifest/package.xml --target-org MySandboxAfter it runs, your project folder contains files that describe Invoice__c and the two Apex classes. You will not find any invoice records there. Retrieving is not part of the change set process, but it gives you a direct view of what a change set will carry. It is a good way to compare the source org with what you plan to send.
The flow of a deployment, at a high level
The diagram shows what crosses between orgs and what stays behind.
The dashed line from the sandbox data ends at a dead end on purpose. Nothing in the change set mechanism reads those records.
Edge cases to keep in mind
- Metadata that references data. A component can contain a hard-coded record ID, such as a flow that assigns work to a specific queue or a report filtered on a record's ID. The ID belongs to the source org. The same record will have a different ID in the target org, or no record at all. Review such references after deployment.
- Existing data and new required fields. Deploying a new required field is a metadata change, but it acts on records that already exist in production. Records created earlier have no value for it. Plan for how those records will be updated.
- Field type changes. Metadata changes can affect stored data. Changing a field's type or length in the sandbox is a definition change. When it is deployed, it can fail or alter how existing production data is handled. Test these changes before you deploy.
- Deleting metadata. Change sets add and update components. They do not remove components from the target org. Removing something takes a separate action, which the limitations chapter covers.
- Profiles and permissions. Who can use a component is also configuration. What reaches the target org depends on which permission-related components you include, and later chapters return to this.
Why this matters for the rest of the tutorial
Every step that follows is about metadata: building the list, finding dependencies, uploading, validating and deploying. When a step behaves in a way that seems odd, ask two questions. Is the item metadata or data? Does the target org have everything the metadata refers to? Those two questions explain most of what you will see.
Exercise
A teammate builds a change set that includes the custom object Invoice__c, its fields and an Apex class InvoiceService. The sandbox holds 500 test invoice records. After deploying to production, they open the Invoices tab and find it empty. Did the deployment fail? Explain, and say how they could get the records into production.
Show answer
The deployment did not fail. A change set carries metadata, which is the definition of Invoice__c, its fields and the Apex class. The 500 invoice records are data, so they stay in the sandbox. Production receives the object with zero records. If the records are actually needed, they must be loaded by a data tool, such as the Data Import Wizard or Data Loader, or entered by users. For test records from a sandbox, you would normally not copy them to production at all.
Exercise
Look at each item and label it metadata or data: (a) a validation rule on Account, (b) the account named "Acme Corp", (c) a page layout, (d) a flow, (e) a case record. Which of these can a change set carry?
Show answer
(a) metadata, (c) metadata and (d) metadata can be carried by a change set. (b) data and (e) data cannot. The test is whether the item defines how the org is built or behaves (metadata), or is an entry stored using that structure (data).
Exercise
A flow in the sandbox assigns cases to a queue and refers to the queue by its record ID. You deploy the flow to production. Why might it misbehave, and what should you check?
Show answer
The queue's ID is part of the data of the sandbox, and IDs differ between orgs. The flow is metadata and deploys fine, but the hard-coded ID may point to nothing in production. Check that the queue exists in production and update the flow to refer to the production queue, preferably by name or through a lookup, not a fixed ID.