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:
- Initialize Repository
mkdir SalesforceProject
cd SalesforceProject
git init
- Add Files
git add force-app/main/default/classes/InvoiceHandler.cls
- Commit Changes
git commit -m "Add InvoiceHandler Apex class"
- Create Feature Branch
git checkout -b feature/invoice-handler
- Merge Feature to Develop Branch
git checkout develop
git merge feature/invoice-handler
- Push Changes to Remote Repo
git push origin develop
Tips:
- Always pull latest changes before starting a new branch:
git pull origin develop
- 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:
- Install VS Code.
- Install Salesforce Extensions Pack:
- Salesforce CLI Integration
- Apex Language Support
- Lightning Web Components Support
- Connect VS Code to Salesforce Org
sfdx force:auth:web:login -a DevOrg
- Opens a browser for login.
- Alias
DevOrgallows easy referencing later. - Retrieve Metadata
sfdx force:source:retrieve -m ApexClass:InvoiceHandler
- Edit Code
- Open
InvoiceHandler.clsin VS Code. - Example:
public class InvoiceHandler {
public static void sendInvoice(Id invoiceId) {
System.debug('Sending invoice: ' + invoiceId);
}
}
3. Salesforce CLI (SFDX)
SFDX Commands with Examples:
- Authorize Org
sfdx force:auth:web:login -a SandboxOrg
- Retrieve Metadata
sfdx force:source:retrieve -m ApexClass:InvoiceHandler
- Deploy Metadata
sfdx force:source:deploy -p force-app/main/default/classes/InvoiceHandler.cls
- 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
- Scenario: Deploy
InvoiceHandlerfrom sandbox to production. - Create a User Story in Copado.
- Add metadata (
InvoiceHandler.cls) to the user story. - Validate deployment in Sandbox.
- Promote to Production.
b) Gearset Example
- Compare source sandbox with target org.
- Select changed metadata.
- Click Deploy.
- Run automated tests before final deployment.
c) AutoRABIT Example
- Schedule nightly deployment from Dev sandbox to QA org.
- Run regression tests automatically.
- 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:
- Feature branch
feature/invoice-handlerdeveloped. - PR reviewed → merged to
develop. - Release branch
release/1.0created → merged tomasterfor production.
7. Release Management Process
Example: Salesforce Release Deployment
- Plan Release
- Features: InvoiceHandler, new Flow automation
- Release window: Sunday 10 PM
- Prepare Environment
- Sync Sandbox metadata:
sfdx force:source:pull
- Develop & Test
- Feature branch:
feature/invoice-handler - Run Apex tests:
sfdx force:apex:test:run -l RunLocalTests
- Deploy to Staging
sfdx force:source:deploy -p force-app/main/default --testlevel RunLocalTests
- Validate
- QA executes UAT.
- Ensure InvoiceHandler triggers are working.
- Deploy to Production
- Use Copado or SFDX:
sfdx force:source:deploy -p force-app/main/default --targetusername ProdOrg --testlevel RunLocalTests
- Post-Deployment
- Verify logs and functionality.
- Document deployment results.