Salesforce Dev Projects Setup & Change Tracking

High-Level Steps:

  1. Clean Up Connected/Authenticated Orgs as Needed
    • sfdx org list
    • Delete Unneeded Scratch orgs from the Dev Hub org: App Launcher > “Active Scratch Orgs”
  2. Set Up a New Salesforce DX Project
    • sfdx org login web -d -a DevHub
    • sfdx force:project:create -n NameTBD
    • VS Code command: SFDX: Create a Default Scratch Org
    • VS Code command: SFDX: Set a default org
    • sfdx org open
  3. Set Up Source Control on GitHub
    • See Below
  4. Make Configuration Changes and Pull Down Source
    • sfdx force source pull
  5. As Needed, Push the Source into New Scratch Orgs
    • sfdx force source push
  6. To Migrate Data to/from the Scratch Org using DataLoader, Make Sure You Have Password for Default Admin User
    • sfdx force:user:password:generate --target-org <username>
    • sfdx org:display --target-org <username>

Detailed Steps:

1. Clean Up Connected/Authenticated Orgs As Needed

  1. View all connected orgs with sfdx org list (formerly sfdx force:org:list).
  2. Mark (some of your) your scratch orgs for deletion with sfdx org list --clean.
  3. In the Dev Hub org, go to App Launcher > “Active Scratch Orgs.” Use the list to delete any unneeded scratch orgs.
  4. To remove other orgs showing up under sfdx org list, delete the JSON files located at ~/.sfdx on your local machine.

2. Set Up a New Salesforce DX Project

  1. Create a new Trailhead Playground and get its credentials. Ex: [email protected]
  2. Via Setup > Quick Find > “Dev” > Dev Hub. Then Enable Dev Hub.
  3. Create an alias DevHub (-a DevHub) and make it the default org (-d) via sfdx org login web -d -a DevHub. Use the credentials from previous steps to log in.
  4. Create an empty directory to hold the Salesforce DX project created in the next step.
  5. From the empty directory created above, create a project called JobApplications via: sfdx force:project:create -n NameTBD
  6. cd into the newly created folder.
  7. Create a new scratch org within VS Code via: CTRL-SHIFT-P then using command SFDX: Create a Default Scratch Org.
    Use the sfdx-project.json file and a 30 day duration.
    Or, use the command: sfdx force:org:create -s -f config/project-scratch-def.json -a --durationdays 30 NameTBD. Either command should set the new scratch org as the default.
  8. Switch between scratch orgs with the command SFDX: Set a default org.
  9. Log into the scratch org with sfdx org open. Since the scratch org was set as default using -s the system stores the authentication token and uses it log in for you.

Note: You can also confirm the successful creation and linking of the scratch org from your Dev Hub org from App Launcher > Active Scratch Orgs

sfdx-project.json:

{
  "packageDirectories": [
    {
      "path": "force-app",
      "default": true
    }
  ],
  "name": "JobApplications",
  "namespace": "",
  "sfdcLoginUrl": "https://login.salesforce.com",
  "sourceApiVersion": "57.0"
}

3. Set Up Source Control on GitHub

  1. Set up a new GitHub repository from github.com/new.
  2. cd into the project folder.
  3. Follow the usual steps GitHub provides to create a new git repository on the command line:
    • echo "# jobapplications" >> README.md
    • git init
    • git add README.md
    • git commit -m "first commit"
    • git branch -M main
    • git remote add origin https://github.com/<your_github_username>/<github-repository-name>
    • If you are using personal access tokens, retrieve the access token, then use git remote set-url origin https://<github-token>@github.com/<username>/<repository-name>.git, replacing <github-token> with the access token
    • git push origin main
  4. Use the usual steps to add changes, commit them, and push them to GitHub:
    • git add .
    • git commit -m "Some message"
    • git push origin main

4. Make Configuration Changes and Pull Down Source

  1. Make any configuration changes needed using declarative tools.
  2. Sync changes made in the scratch org to local DX project via sfdx source pull.
  3. Use the usual steps to add changes, commit them, and push them to GitHub:
    • git add .
    • git commit -m "Some message"
    • git push origin main

5. As Needed, Push the Source into New Scratch Orgs

  • The command sfdx force source push will push the source code into the default scratch org.

6. To Migrate Data to/from the Scratch Org using DataLoader, Make Sure You Have Password for Default Admin User

  1. Use the command sfdx force:user:password:generate --target-org <username> to generate a password for the admin user
  2. Thereafter, use the command sfdx org:display --target-org <username> to see the password