Sub topic 4
Data versus Metadata in an Org
This chapter assumes you know what an org is (a single customer's isolated environment on the shared Salesforce platform) and that you understand databases, tables, and records. It covers the split between the two kinds of content an org holds, and why that split drives how you move changes between orgs.
The core distinction
Every org holds two kinds of content.
- Data is the business records your users create and change: an Account called "Acme", a Contact named Ana Silva, an Opportunity worth 50,000. Data lives in rows, one per record.
- Metadata is the configuration that describes how the org is structured and how it behaves: which objects exist, which fields they have, page layouts, validation rules, automations, Apex code, permission sets, and so on.
A useful rule of thumb: if you would call it a "record", it is data. If you would call it a "setting", "definition", or "code", it is metadata.
| Question | Data | Metadata |
|---|---|---|
| Example | An Opportunity named "Acme Renewal" | The Opportunity object and its Amount field |
| Created by | Users, integrations, data loads | Admins and developers |
| Typical volume | Thousands to millions of rows | Hundreds to thousands of components |
| Moved between orgs with | Data Loader, Data Import Wizard, APIs, Bulk API | Change sets, Salesforce CLI, packages, metadata API |
| Lives in version control | Rarely | Usually |
How the platform uses metadata
Salesforce is multi-tenant. All customers share the same underlying code and infrastructure. Your org differs from another org only because of its metadata and its data. The platform reads your org's metadata at run time to decide what to show and what to enforce. When an admin adds a custom field, no one rebuilds an application. A metadata row is added, and the platform starts rendering and validating that field.
This is why Salesforce is described as a metadata-driven platform. The same shared engine becomes a different application for each org.
Where the line gets blurry
The rule of thumb works most of the time, but several cases need care.
- Custom metadata types and custom settings. These define configuration, but the values you store in them are records. Custom metadata type records are deployable as metadata. Custom settings values are data, and they do not move with a deployment.
- Standard picklist values and record types. Record types and picklist values are metadata, even though users see them when editing a record. The chosen value on a specific record is data.
- Reports and dashboards. The report definition is metadata. The numbers it shows are computed from data.
- Users. A User record is data. The profile and permission sets assigned to it are metadata. Assignments of permission sets to users are data, so a deployment does not copy them.
- Email templates, documents, and static resources. These are stored as files or records but are treated as metadata components when you deploy them.
Why the split matters for environments
The split is the reason org types exist, which later chapters cover. Production holds real data and live metadata. A sandbox is a copy of production's metadata, and some sandbox types also copy data. A scratch org is built from metadata and starts with no data.
The common workflow follows from this:
- Build or change metadata in a non-production org.
- Test it with safe data.
- Deploy the metadata to production.
- Never copy test data into production by accident.
Metadata flows toward production. Data usually flows the other way, from production into test environments (and only to the extent the sandbox type allows, and often masked).
Seeing metadata for yourself
You can see metadata directly. In Setup, Object Manager lists objects and their fields. From the command line, the Salesforce CLI can retrieve metadata as files. A project manifest named package.xml lists the components you want:
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>Account</members>
<name>CustomObject</name>
</types>
<version>60.0</version>
</Package>Retrieve it with the CLI (run this inside a Salesforce DX project, with an authorized org):
sf project retrieve start --manifest package.xml --target-org my-orgThe result is an XML file describing the Account object: its fields, layouts, and settings. No Account records are in it. That absence is the point: metadata and data are separate things, retrieved and deployed through separate tools.
You can also query the data side with SOQL:
SELECT Id, Name, Industry FROM Account LIMIT 5This returns rows (data). To list the fields that exist (metadata), use the describe call through the API or the Object Manager. SOQL itself reads data, not definitions.
Common errors
- Assuming a deployment moves records. A change set that includes a custom object moves the object definition only. Records stay behind.
- Deploying a field that code or a flow references before the field exists. Dependencies between metadata components must arrive together or in the right order.
- Forgetting that profile and permission settings are metadata. If a new field is invisible to users in the target org, field-level security was probably not deployed with it.
- Testing against empty data. A scratch org has no records, so tests that rely on existing records fail. Create the records in the test itself or load seed data.
- Treating a sandbox as production-safe for sensitive data. If a sandbox copies production data, it may expose real customer information. Use masking where it matters.
Edge cases to remember
- Some changes are both: deleting a custom field removes the metadata and also discards the data stored in it. Salesforce keeps a deleted field recoverable for a limited period, so it is not an instant loss, but the data is gone from normal use.
- Changing a field's type, such as text to number, is a metadata change that can affect existing data and may be blocked or may lose values.
- Metadata API versions matter. Components declare an API version, and behavior can differ between versions.
Exercise
Your team adds a custom field "Renewal Date" to Opportunity in a sandbox, plus a validation rule that requires it. You deploy to production with a change set. Users report that existing Opportunities now fail to save until someone fills in a date. What kind of content did you move, what did you not move, and what should you have done?
Show answer
You moved metadata (the field definition and the validation rule). No data moved, so existing production Opportunities have no Renewal Date, and the rule blocks edits to them. You should have loaded or backfilled the date values (data) before or with activating the rule, or deployed the rule inactive and activated it after the data was ready, or made the rule apply only to new or changed records.
Exercise
Classify each as data or metadata: (a) a Contact named Ana Silva, (b) a page layout for Contact, (c) the assignment of a permission set to Ana's user, (d) an Apex class.
Show answer
(a) data, (b) metadata, (c) data, because assignments are records and are not copied by deployment, (d) metadata.