Salesforce DevOps & Release Engineering - Textnotes

Salesforce DevOps & Release Engineering


This module teaches how Salesforce applications are built, versioned, deployed, and released using DevOps tools and processes. You will learn Git, VS Code, SFDX, deployment strategies, DevOps automation tools, and release management best practices—skills required for Salesforce Admin + Developer + DevOps roles.

1. Git Basics

Git is the backbone of version control in Salesforce DevOps. Here’s how it works in practice.

Scenario Example:

You are developing a new Apex class called InvoiceHandler.

Steps:

  1. Initialize Repository

mkdir SalesforceProject
cd SalesforceProject
git init
  1. Add Files

git add force-app/main/default/classes/InvoiceHandler.cls
  1. Commit Changes

git commit -m "Add InvoiceHandler Apex class"
  1. Create Feature Branch

git checkout -b feature/invoice-handler
  1. Merge Feature to Develop Branch

git checkout develop
git merge feature/invoice-handler
  1. Push Changes to Remote Repo

git push origin develop

Tips:

  1. Always pull latest changes before starting a new branch:

git pull origin develop
  1. Use descriptive commit messages:

"Fix null pointer in InvoiceHandler" instead of "Update class"

2. VS Code Setup

VS Code is the primary IDE for Salesforce development.

Steps with Example:

  1. Install VS Code.
  2. Install Salesforce Extensions Pack:
  3. Salesforce CLI Integration
  4. Apex Language Support
  5. Lightning Web Components Support
  6. Connect VS Code to Salesforce Org

sfdx force:auth:web:login -a DevOrg
  1. Opens a browser for login.
  2. Alias DevOrg allows easy referencing later.
  3. Retrieve Metadata

sfdx force:source:retrieve -m ApexClass:InvoiceHandler
  1. Edit Code
  2. Open InvoiceHandler.cls in VS Code.
  3. Example:

public class InvoiceHandler {
public static void sendInvoice(Id invoiceId) {
System.debug('Sending invoice: ' + invoiceId);
}
}

3. Salesforce CLI (SFDX)

SFDX Commands with Examples:

  1. Authorize Org

sfdx force:auth:web:login -a SandboxOrg
  1. Retrieve Metadata

sfdx force:source:retrieve -m ApexClass:InvoiceHandler
  1. Deploy Metadata

sfdx force:source:deploy -p force-app/main/default/classes/InvoiceHandler.cls
  1. Run Apex Test

sfdx force:apex:test:run -n InvoiceHandlerTest

Example Test Class:


@IsTest
private class InvoiceHandlerTest {
@IsTest static void testSendInvoice() {
Test.startTest();
InvoiceHandler.sendInvoice('001xx000003DGbXAAW');
Test.stopTest();
}
}

4. Retrieve & Deploy Metadata

Example: Retrieve Multiple Metadata


sfdx force:source:retrieve -m ApexClass,CustomObject,Flow

Example: Deploy Changes


sfdx force:source:deploy -p force-app/main/default

Example Deployment with Test Run


sfdx force:source:deploy -p force-app/main/default --testlevel RunLocalTests

5. DevOps Tools

a) Copado Example

  1. Scenario: Deploy InvoiceHandler from sandbox to production.
  2. Create a User Story in Copado.
  3. Add metadata (InvoiceHandler.cls) to the user story.
  4. Validate deployment in Sandbox.
  5. Promote to Production.

b) Gearset Example

  1. Compare source sandbox with target org.
  2. Select changed metadata.
  3. Click Deploy.
  4. Run automated tests before final deployment.

c) AutoRABIT Example

  1. Schedule nightly deployment from Dev sandbox to QA org.
  2. Run regression tests automatically.
  3. Backup metadata before deployment.

6. Version Control Branching Strategy

Example Workflow (Git Flow):


master → Production-ready code
develop → Integrates all features
feature/invoice → Work on invoice functionality
hotfix/bug-001 → Fix urgent production bug

Scenario:

  1. Feature branch feature/invoice-handler developed.
  2. PR reviewed → merged to develop.
  3. Release branch release/1.0 created → merged to master for production.

7. Release Management Process

Example: Salesforce Release Deployment

  1. Plan Release
  2. Features: InvoiceHandler, new Flow automation
  3. Release window: Sunday 10 PM
  4. Prepare Environment
  5. Sync Sandbox metadata:

sfdx force:source:pull
  1. Develop & Test
  2. Feature branch: feature/invoice-handler
  3. Run Apex tests:

sfdx force:apex:test:run -l RunLocalTests
  1. Deploy to Staging

sfdx force:source:deploy -p force-app/main/default --testlevel RunLocalTests
  1. Validate
  2. QA executes UAT.
  3. Ensure InvoiceHandler triggers are working.
  4. Deploy to Production
  5. Use Copado or SFDX:

sfdx force:source:deploy -p force-app/main/default --targetusername ProdOrg --testlevel RunLocalTests
  1. Post-Deployment
  2. Verify logs and functionality.
  3. Document deployment results.