Episode 0. Salesforce Deployment SFDX Know how!

Taken from google

Salesforce DX is put together a set of tools, features and APIs to make it easier for Salesforce teams to adopt modern DevOps. see it like a toolkit to strengthen better adoption of devops.

It encourages developers to adopt best practices for software development stacks, like using version control, and automating more parts of the release process, scripts etc.

Remember in itself DX may not necessarily perform all the devops processes as standalone but it brings on table all the blocks you need to connect with other elements — jenkins for scheduling or automation, github or bitbucket for source control,

  1. Database Schema; user interface; automation (workflows, process builders and flows),reports, code

Develop on Local source → Scratch Org →Source Control (e.g. github)→ Sandbox → production
1. Software developer works in local project repo , develops the functionality (code & config) and push to scratch org
2. In the Scratch or, it is tested & pulled back to local repo.
3. Next once tested, then finally the code goes to source Control repositry (this is the source of *TRUTH)

Thumb rule to remember is this process:


Source:Taken from Google

Lets kickstart with a project (A →:F)

A. First Create a SFDX project

  1. Go to your commandline (window + R= keyboard shortcut) and run this command → sfdx force:project:create — projectname sfdx-Mo
  2. cd sfdx-Mo (this is to change project directory)
  3. Create assets folder manually: create package.xml and use the command below to retrieve content from the org to assets folder → sfdx force:source:retrieve — manifest assets/package.xml — targetusername DevHub — wait 10
  4. Export sample data from org → sfdx force:data:tree:export — targetusername DevHub — outputdir assets/data — query “SELECT Id, Name, Email__c, Phone__c, Mobile_Phone__c, Title__c, Zip__c FROM Properties__r ) FROM Broker__c”

Once project is created we need to:

B. Add our Salesforce DX project to our GIT source Control, for this :

  • Create a GitHub repository at https://github.com/new, name it & next open cmd prompt type below
  • git config — global user.name “EMEAMo…..”
  • git config — global user.email “mohitchha….”

  • git init

git add .
git commit — message “Initial commit of myproject metadata” (this commits the added files as a snapshot to the project’s version history)

C. Another Colleague starts in & joins the project, Here comes dev expert 2 Maria (see how she collaborate)

  1. She starts by cloning the parent (master) branch to its local repositry
    git clone https://github.com/EMEAMo../sfdx-project.git sfdx-maria
  2. Then She creates a new feature branch →git checkout -b feature-maria-util→ Then she creates some apex classes (in class folder)
  3. Create & Push metadata to scratch org → sfdx force:org:create — setdefaultusername — setalias sfdx-maria — definitionfile config/project-scratch-def.json
  4. Sfdx force:source:push (to deploy)
  5. Export some sample data from Devhub → sfdx force:data:tree:export — targetusername DevHub — outputdir assets/data — query “SELECT Id, Name, Email__c, Phone__c, Mobile_Phone__c, , Location__Longitude__s, Status__c, Tags__c, Thumbnail__c, Title__c, Zip__c FROM Properties__r ) FROM Broker__c”
  6. Assign the permission set to the dreamhouse app → sfdx force:user:permset:assign — permsetname DreamHouse
  7. Import sample data → sfdx force:data:tree:import -f assets/data/Broker__c-Property__c.json
  8. Run Tests to Validate Changes →sfdx force:apex:test:run — codecoverage — resultformat human — wait 2
  9. Pull Metadata from Scratch Org
    sfdx force:source:pull
  10. Lastly, add the changes to the source control

    - git add .
    - git commit — message “Added new apex class- util.class”
    - git push -u origin feature-maria-util

Conclusion: with this her code changes goes to her new respective feature branch, Next she needs to open pull request to merge changes into the master branch.

  1. sfdx force:auth:web:login -d -a DevHub (to authorize against the Devhub)
  2. sfdx force:org:open -u DevHub (to open your devhub)
  3. sfdx force:org:list (shows all the scratch orgs& org list)
  4. Create a Salesforce DX project: sfdx force:project:create -n MyFirstProject File elements woth checking are: sfdx-project.json; config/project-scratch-def.json & force-app; — cd MyFirstProject (change directory)
  5. sfdx force:org:create -s -f config/project-scratch-def.json -a MyScratchOrg( this is to create a scratch org)
  6. Create data in scratch org: sfdx force:data:record:create -s Account -v “Name=’Marriott Marquis’ BillingStreet=’780 Mission St’ BillingCity=’San Francisco’ BillingState=’CA’ BillingPostalCode=’94103' Phone=’(415) 896–1600' Website=’www.marriott.com’
  7. Export data from Salesforce: sfdx force:data:tree:export -q “SELECT Name, BillingStreet, BillingCity, BillingState, BillingPostalCode, Phone, Website FROM Account WHERE BillingStreet != NULL AND BillingCity != NULL and BillingState != NULL” -d ./data
  8. Import .json file to any org: sfdx force:data:tree:import — sobjecttreefiles data/Account.json
  9. Open the scratch org: sfdx force:org:open -u test-au9akadu7o6z@exam.. OR -u MyScratchOrg (sc. org alias)
  10. Create an apex class: sfdx force:apex:class:create -n AccountSearchController -d force-app/main/default/classes
  11. sfdx force:source:push -u MyScratchOrg (against the scratch org)
  12. sfdx force:source:pull
  13. sfdx force:org:delete -u MyScratchOrg
  14. To Convert Source to metadata api → This converts sfdx source format to metadata format which creates also package.xml
  15. To Convert metadata from metadata api format to source format, SFDX one: →

E. Here are some of the powerful tasks that can be used directly through the command line:

  1. Export (SOQL) / Import (CSV) data
  2. Bulk API Delete/Upserts
  3. Full CRUD on individual records
  4. Run Anonymous Apex and Apex Tests
  5. Deploy/Retrieve/List Metadata with Metadata API
  6. List and Open in a browser a connected Salesforce instance
  7. Create/Delete scratch orgs
  8. Create/Version/Install packages
  9. Create/Display Users and Assign permission sets to them
  10. Convert between SFDX Component Structure and Metadata API Structure

F. Tools available today for moving metadata (deployment)

  1. Change sets
  2. Ant migration tool
  3. SFDX and Source related commands
  4. Packages

Please Note: For few elements in the article, references are taken from online articles & docs, incase you find similarities , please dont be surprised :)

For more learning, please refer to trailheads- SFDX & GIT :


A useful utlity to see what DX supports and comparsion with others: https://mdcoverage.secure.force.com/docs/metadata-coverage/50

Thanks! Mc



Program Architect at Salesforce, 26x Certified

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store