Deployment and CI/CD Patterns

Overview

This guide covers Salesforce deployment strategies, source control patterns, deployment best practices, Metadata API usage, and package development patterns. These patterns are essential for managing Salesforce development lifecycle and ensuring reliable deployments.

Related Patterns:

Consensus Best Practices

Deployment Methods

Change Sets

When to use:

Limitations:

Metadata API

When to use:

Advantages:

Salesforce DX (SFDX)

When to use:

Advantages:

Source Control Strategies

Git Workflow Patterns

Branching Strategy:

Commit Patterns:

Metadata Organization

Directory Structure:

force-app/
β”œβ”€β”€ main/
β”‚   β”œβ”€β”€ default/
β”‚   β”‚   β”œβ”€β”€ classes/
β”‚   β”‚   β”œβ”€β”€ triggers/
β”‚   β”‚   β”œβ”€β”€ lwc/
β”‚   β”‚   β”œβ”€β”€ flows/
β”‚   β”‚   └── objects/
β”‚   └── test/
└── metadata/

Best Practices:

Deployment Best Practices

Pre-Deployment Validation

Checklist:

Deployment Process

Steps:

  1. Validate: Run validation deployment
  2. Review: Review validation results
  3. Deploy: Execute deployment
  4. Verify: Verify deployment success
  5. Test: Run smoke tests
  6. Monitor: Monitor for issues

Rollback Strategies

Approaches:

Metadata API Patterns

Metadata API Deployment

Use Cases:

Patterns:

Metadata API Retrieval

Use Cases:

Patterns:

Package Development Patterns

Unlocked Packages

When to use:

Patterns:

Managed Packages

When to use:

Patterns:

Q&A

Q: What deployment methods are available in Salesforce?

A: Deployment methods: (1) Change Sets - for small, ad-hoc deployments between connected orgs, (2) Metadata API - for programmatic deployments, CI/CD integration, (3) Salesforce DX (SFDX) - modern source-driven workflow, (4) Unlocked Packages - for modular, versioned components, (5) Ant Migration Tool - command-line deployment tool. Choose based on project needs and workflow preferences.

Q: When should I use Change Sets vs. Metadata API vs. SFDX?

A: Use Change Sets for: small deployments, non-technical users, quick fixes. Use Metadata API for: programmatic deployments, CI/CD integration, automated deployments. Use SFDX for: new projects, modern development workflow, source-driven development, scratch orgs. SFDX is recommended for new projects, Metadata API for automation, Change Sets for simple deployments.

Q: How do I implement source control for Salesforce?

A: Implement source control by: (1) Using Git for version control, (2) Storing all metadata in source control, (3) Using SFDX for source-driven development, (4) Using branching strategies (feature branches, main branch), (5) Committing frequently (small, logical commits), (6) Using pull requests for code review, (7) Tagging releases (version tags for deployments).

Q: What should be included in a deployment checklist?

A: Include in checklist: (1) Metadata backup (export before deployment), (2) Test execution (all tests pass, coverage met), (3) Validation (validate deployment, no errors), (4) Security review (profiles, permission sets), (5) Rollback plan (documented, tested), (6) Communication (notify stakeholders), (7) Monitoring (watch for errors after deployment), (8) Documentation (deployment notes, changes).

Q: How do I implement rollback strategies?

A: Implement rollback by: (1) Backing up metadata before deployment (version control, export), (2) Creating rollback scripts (reverse deployment steps), (3) Testing rollback procedures in sandbox, (4) Documenting rollback steps (clear instructions), (5) Using version control to track changes, (6) Planning rollback before deployment (not after issues), (7) Automating rollback where possible.

Q: What are unlocked packages and when should I use them?

A: Unlocked packages are versioned, modular components for Salesforce. Use them for: (1) Modular development (break down large codebases), (2) Reusable components (share across projects), (3) Version management (version components independently), (4) Dependency management (manage dependencies between components), (5) Team collaboration (independent team development). Unlocked packages provide better organization than monolithic deployments.

Q: How do I use the Metadata API for deployments?

A: Use Metadata API by: (1) Retrieving metadata from source org, (2) Deploying metadata to target org, (3) Validating deployments (dry-run validation), (4) Handling deployment errors (parse error messages, fix issues), (5) Automating deployments (scripts, CI/CD integration), (6) Tracking deployment status (monitor deployment progress). Metadata API enables programmatic, automated deployments.

Q: What are best practices for Salesforce deployments?

A: Best practices include: (1) Use source control (all metadata version controlled), (2) Validate before deploying (always run validation), (3) Use deployment checklists (comprehensive checklists), (4) Implement rollback strategies (plan for failures), (5) Test thoroughly (run all tests before production), (6) Automate deployments (CI/CD pipelines), (7) Document deployments (deployment notes, changes), (8) Monitor after deployment (watch for errors).

Q: How do I handle deployment conflicts?

A: Handle conflicts by: (1) Identifying conflicts (metadata conflicts, dependency issues), (2) Resolving conflicts (merge changes, update dependencies), (3) Testing resolution (verify conflicts resolved), (4) Coordinating deployments (avoid simultaneous deployments), (5) Using source control (track changes, merge properly), (6) Communicating changes (notify team of deployments), (7) Planning deployments (coordinate to avoid conflicts).

Q: What is the difference between validation and deployment?

A: Validation runs tests and checks without deploying (dry run). Deployment actually applies changes to the org. Always validate before deploying to production. Validation catches errors without affecting the org, while deployment makes changes permanent. Use validation in CI/CD pipelines to catch issues early, then deploy after validation passes.