Sub topic 5
Creating an outbound change set
This chapter assumes you can work in Setup, know the difference between a sandbox and a production org, and have a user with the Deploy Change Sets permission. It also assumes you have already authorized a deployment connection from your source org to the target org.
What an outbound change set is
An outbound change set is the version you build and send from the source org. It is a named list of metadata components. It holds no data records. When you upload it, Salesforce copies the listed components to the target org, where they appear as an inbound change set.
You can only create outbound change sets in an org that has a deployment connection to the target. Build in the sandbox, not in production.
Create the change set
- In the source org, open Setup and search for Outbound Change Sets.
- If a welcome page appears, click Continue.
- In the Change Sets list, click New.
- Enter a Name, for example
Invoice_Release_1. Add a Description that says what the change set is for. The target org shows both, so they help the person who deploys it. - Click Save.
The new change set opens on a detail page with two lists: Change Set Components and Change Set History. The history stays empty until you upload.
Add components
- In Change Set Components, click Add.
- Choose a Component Type, such as Custom Object or Apex Class.
- Select the components you want. Use the search and filter controls if the list is long.
- Click Add To Change Set.
Repeat for each type. A component is identified by its type and its name. That is the same pairing a package.xml manifest uses, so you can read a change set as a manifest you build by clicking.
<?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>This manifest lists the same kind of content a change set would hold: one custom object and two Apex classes.
To compare the source org with your selection, retrieve the same components from the sandbox:
sf project retrieve start --manifest manifest/package.xml --target-org MySandboxChoose what to include
Adding an object does not always carry everything attached to it. Check these cases:
- Custom fields: Adding a custom object includes its fields, but adding a standard object does not. Add the custom fields you need by type.
- Page layouts, record types, and validation rules: Add these explicitly if the target needs them.
- Profiles and permission sets: Add them with View/Add Dependencies or by type. A profile in a change set carries settings only for the components in that change set.
- Apex classes: Include the test classes. Production requires tests to run when you deploy Apex.
The next chapter covers finding dependent components in detail. For now, click View/Add Dependencies once to see what Salesforce suggests.
The lifecycle of an outbound change set
Common mistakes
- Building in the wrong org. Outbound change sets exist only where you create them. Check the org name in the header before you start.
- Forgetting test classes. A deployment to production can fail because the Apex classes have no tests.
- Reusing a name. Give each release a clear name. Vague names like
Testmake the target's inbound list hard to read. - Assuming data moves. Records in
Invoice__cstay in the sandbox.
Exercise
You added the custom object Invoice__c and the class InvoiceService to an outbound change set. Which two extra checks should you make before uploading?
Show answer
Check that the test class (such as InvoiceServiceTest) is included, since production deployments of Apex need tests. Also run View/Add Dependencies to find related components, such as fields on standard objects, page layouts, or permission settings, that the target org needs.