Ora

How to deploy data from sandbox to production?

Published in Salesforce Deployment 6 mins read

Deploying from a sandbox environment to production involves moving validated configurations, code, and sometimes data from a testing ground to the live system. This process is crucial for implementing new features, bug fixes, and system enhancements reliably.

Understanding Deployment in Sandbox to Production

Deployment is the systematic transfer of changes from a development or testing environment (sandbox) to a production environment. The primary goal is to ensure that new functionalities work as expected without disrupting live operations. The specific tools and methods used often depend on the type of changes being deployed – whether it's metadata (configurations, code, object structures) or actual record data.

Metadata Deployment: Using Change Sets and Advanced Tools

Metadata refers to the structure of your application, including custom objects, fields, Apex classes, Visualforce pages, workflows, page layouts, profiles, and more. For Salesforce environments, the native tool for moving metadata is a Change Set.

When you log into any Salesforce environment, be it a sandbox or production, you can search for "Change Sets." You will find two types: Outbound Change Sets and Inbound Change Sets.

  • Outbound Change Set: Created in the source environment (your sandbox) to package components you want to deploy.
  • Inbound Change Set: Received in the target environment (production) to deploy the components from the outbound change set.

Step-by-Step Guide to Deploying Metadata with Change Sets

  1. Create an Outbound Change Set in Sandbox:

    • Navigate to Setup in your sandbox environment.
    • Search for "Outbound Change Sets" in the Quick Find box.
    • Click New to create a new change set, providing a name and description.
    • Add Components: Click Add to select the specific metadata components you wish to deploy. This could include:
      • Custom Objects and Fields
      • Apex Classes and Triggers
      • Visualforce Pages and Components
      • Workflows, Process Builders, and Flows
      • Layouts, Record Types, Profiles, and Permission Sets
      • Reports and Dashboards (though often recreated in production to avoid data dependencies)
    • Add Dependent Components: After adding your main components, click View/Add Dependencies to ensure all necessary components (like custom fields for an Apex class) are included.
    • Upload the Change Set: Once all components are added and validated, click Upload and choose your target production organization.
  2. Validate and Deploy the Inbound Change Set in Production:

    • Log in to your production environment.
    • Navigate to Setup and search for "Inbound Change Sets."
    • You will see the uploaded change set from your sandbox listed under "Change Sets Awaiting Deployment."
    • Validate: Before deploying, it's highly recommended to first Validate the change set. This process simulates the deployment and checks for any errors or conflicts without actually applying the changes. It helps identify issues like missing components or permission problems.
    • Deploy: If validation is successful, click Deploy. The deployment process will then apply all the changes from your sandbox to production. Monitor the deployment status for success or failure.

When to Use Change Sets

Change sets are ideal for small to medium-sized deployments, especially for organizations that don't have complex development processes or frequent releases. They are native to Salesforce and relatively easy to use for administrators.

Advanced Metadata Deployment Tools

For more complex projects, continuous integration/continuous deployment (CI/CD) pipelines, or larger organizations, other tools offer more robust features:

  • Salesforce DX: A developer experience that offers powerful command-line tools for source-driven development, enabling more granular control over metadata and version control integration.
  • Salesforce Ant Migration Tool: A Java/Ant-based command-line utility for moving metadata components between Salesforce orgs using XML files. It's often used for scripting deployments and integrating with CI systems.
  • Third-Party DevOps Tools: Solutions like Copado, Gearset, AutoRABIT, and Flosum provide advanced capabilities for version control, automated testing, change management, and release orchestration.

Data Migration: Moving Record Data

While change sets are for metadata, they do not move actual record data (e.g., Accounts, Contacts, Custom Object records). Deploying new custom objects or fields via a change set creates the structure in production, but the records themselves must be moved separately.

To deploy actual record data from sandbox to production, you typically use data migration tools:

  • Salesforce Data Loader: A desktop application that can insert, update, upsert, delete, or export Salesforce records. You can export data from your sandbox to CSV files and then import it into production.
    • Example: Exporting newly created "Project" records from a custom object in sandbox and importing them into the production "Project" object.
  • Data Import Wizard: A native Salesforce tool (available in Setup) for importing data from CSV files for standard objects and some custom objects. It's suitable for smaller data volumes (up to 50,000 records).
  • Third-Party ETL (Extract, Transform, Load) Tools: Tools like Informatica Cloud, MuleSoft, Talend, or Jitterbit offer more sophisticated data integration capabilities, allowing for complex data transformations, scheduling, and error handling. These are often used for large-scale data migrations or ongoing data synchronization.

Important Considerations for Data Migration:

  • Record IDs: Salesforce record IDs are environment-specific. When moving data, you'll need to map external IDs or use upsert operations to link related records correctly.
  • Parent-Child Relationships: Ensure parent records are migrated before child records to maintain data integrity.
  • Data Cleansing: Use the opportunity to clean and validate data before moving it to production.
  • Security Settings: Ensure users in production have appropriate permissions to view and modify the new data.

Best Practices for Successful Deployments

Successful deployments require careful planning and execution.

  • Comprehensive Testing: Thoroughly test all changes in the sandbox, including unit tests, integration tests, and user acceptance testing (UAT), before deploying to production.
  • Version Control: Utilize a version control system (like Git) to track all metadata changes, providing a historical record and enabling easier collaboration and rollback.
  • Communication: Clearly communicate deployment schedules, potential impacts, and new features to stakeholders and end-users.
  • Backup: Always perform a full backup of your production environment before any major deployment.
  • Rollback Plan: Have a clear plan for how to revert changes if an unforeseen issue arises during or after deployment.
  • Sandbox Refresh Strategy: Regularly refresh your sandboxes to ensure they reflect the latest production configuration and data (though refreshing deletes current sandbox changes, so plan accordingly).
  • Deployment Window: Schedule deployments during off-peak hours to minimize disruption to users.

Deployment Process Overview

Aspect Metadata Deployment Data Migration
Purpose Move application structure, code, configurations. Move actual records (e.g., Accounts, Cases, Custom).
Primary Tools Change Sets, Salesforce DX, Ant Migration Tool, DevOps Data Loader, Data Import Wizard, ETL Tools, APIs
Key Steps Package (Outbound), Validate, Deploy (Inbound) Extract, Transform, Load (ETL)
Considerations Dependencies, Profiles/Permissions, Apex Tests Record IDs, Parent-Child Relationships, Data Quality
Example Deploying a new custom object and its associated Apex Trigger Moving 10,000 new Customer records into the custom object

By understanding these distinct processes and employing best practices, organizations can effectively deploy both metadata and data from sandbox to production, ensuring a stable and functional live environment.