Empower Salesforce Team to run Agile with Continuous Delivery

2017, May 10    

Continuous Delivery and CI with Salesforce is one problem I have thought about for some time. Source driven development with source control is central to CI/CD process. Salesforce for a long time had been doing ORG centric development, based on Production org. On Many Salesforce projects I was able to use source control but it was sort of a crutch used to back up source rather than doing CI. Recently new DX tools been getting more attention as a solution to change a flow to Source and repository based development however, for now real production deployments are still done with ANT or Change Sets.

In our team we have various skill sets but not everyone has command line skills. Typical developers are good with CLI tools for git, heroku or sfdx CLIs. But how about Admins or Declarative Developer who making customizations to models or process?

To include everyone to run development through source control (GitHub) I had to create a deployment tool simple enough for anyone to use that did not require lots of diverse skills on git CLI or ant scripts or shell scripts.

Started this project a while back on GitHub sf-deploy-tool project. Here is my solution

Using Agile Accelerator package make it simple to run Agile Sprints and allows for many UI customization and keeping it all in Salesforce. Our team was used to work on Agile Accelerator Stories with this tool. If you do not yet use Agile Sprint management tool I recommend to try Agile Accelerator, available on AppExchange.

I created a new Story View - Visual Force page to list out all current Sprint stories as Work Items in Agile Accelerator. Ideally I wanted to customize existing Work Item detail page but in Classic it is a Managed package VFP no way to modify it. In Lightning we are able to deploy direct from custom button action on Work Item because it uses standard page layouts. Code found on GitHub sf-agile-deploy-pkg

Next I needed a service to pull metadata and commit source to git repository. Build a good old Java Spring-Boot app with REST services to program all needed actions. I selected Java mainly for easy integration to other tool libraries such as Apache ANT and Jgit to manage deployments.

ANT Migration Tool - a Salesforce deployment tool using ant to pull metadata from source Development org and deploy to target org. I used ANT with Change set to allow SF Users easy selection of metadata items and automatically assemble package.xml deployment file.

JGit - is common Java Git library used to run API with GitHub to work with branches do commits to repository with programmable APIs.

Next Tool is Salesforce REST API to handle Chatter Posts to notify users about deployment results direct on the Story records. Another benefit keeping Agile stories in Salesforce.

Salesforce Webservice Connector WSC - Client Java library used to add package.xml as attachment to Story to keep package per story. Normal git flow will be merging branch stories and package will also merge so individual story components will be lost in the merge. Keeping attachments helps to track that in simple way.

Now assemble several command services that enable simple URL parameters to initiate a deployment. Deploying this tool to Heroku with temporary file storage helps with keeping temp files for deployment no permanent storage, only what is needed during deployment time.

Set up URL to call deployment service from custom button or link on VFP for each story we are able to deploy individual stories/Change sets with simple button push without git CLI and keep source tracking in GitHub. Here is example deployment log visible to user.

Start deployment log...
Deployment Tool - Salesforce Agile Accelerator

*** START INITIAL COMMIT DEPLOYMENT Process - W-001111 ***


0. Cloning from https://github.com/MyOrg/project-salesforce-dev.git to deploystore/W-001111/project-salesforce-dev

1. Cloned repository: deploystore/W-001111/project-salesforce-dev/.git $git clone https://github.com/MyOrg/project-salesforce-dev.git

2. Switch to empty branch to start: $git checkout empty

3. Create new story branch from empty and checkout new branch: $git checkout -b W-001111

4. Run ant to pull changeset from source TESTDev org: $ant pullChangeSet

pullChangeSet:
[sf:retrieve] Request for a retrieve submitted successfully.
[sf:retrieve] Request ID for the current retrieve task: 09Sg0000005GdLeEAK
[sf:retrieve] Waiting for server to finish processing the request...
[sf:retrieve] Request Status: InProgress
[sf:retrieve] Request Status: Succeeded
[sf:retrieve] Finished request 09Sg0000005GdLeEAK successfully.

BUILD SUCCESSFUL
Total time: 13 seconds

5. Add story files to local repo tracking: $git add .

6. Commit story files to local repo with comments: $git commit -m "W-001111 Make it better"

7. Push all committed story files to remote: $git push origin W-001111

8. Run ant to deploy story W-001111 to target TESTQA org: $ant deployChangeSet

deployChangeSet:
[sf:deploy] Request for a deploy submitted successfully.
[sf:deploy] Request ID for the current deploy task: 0Afc000000fI5A6CAK
[sf:deploy] Waiting for server to finish processing the request...
[sf:deploy] Request Status: Pending
[sf:deploy] Request Status: InProgress (0/15)  -- Processing Type: CustomObject
[sf:deploy] Request Status: Succeeded

BUILD SUCCEEDED
/app/build.xml:43: 
*********** DEPLOYMENT SUCCESS ***********
Request ID: 0Afc000000fI5A6CAK


Total time: 21 seconds


9. Post status to chatter @mention assigned user


App repository can be found here sf-deploy-tool

Now everyone on our team is able to contribute to Continuous Delivery with GitHub and learn in the process.