Skip to content

Instantly share code, notes, and snippets.

@doppiomacchiatto
Created January 13, 2020 17:29
Show Gist options
  • Save doppiomacchiatto/0ca9bbe0cb94c39c147380b4de4c9998 to your computer and use it in GitHub Desktop.
Save doppiomacchiatto/0ca9bbe0cb94c39c147380b4de4c9998 to your computer and use it in GitHub Desktop.
Salesforce DX steps, tips, and tricks

Initial Set-Up

Authenticate with Dev Hub (one time)

The Dev Hub is our production org. Scratch orgs are registered against a Dev Hub and can be managed from there. Execute the following command in a terminal (you'll be prompted to enter your username and password in a browser window):

  • sfdx force:auth:web:login --setdefaultdevhubusername -a Unum_DevHub

Set Your Default Dev Hub Username

It's possible to have multiple Dev Hub orgs. If you want to change to a different Dev Hub, you must specify your defaultdevhubusername setting with this command:

Create a Scratch Org

  • sfdx force:org:create -s -f config/project-scratch-def.json -a Portal_C1_Common_Scratch -d 15

Note: Portal_C1_Common_Scratch is this example's scratch org name; -d 15 is the duration, how many days until the scratch org expires.

List Orgs

  • sfdx force:org:list

Install Lighting Test Service

  • sfdx force:lightning:test:install

Deploy Content

  • sfdx force:mdapi:deploy -d deploy_pre_steps -u Portal_C1_Common_Scratch
  • sfdx force:mdapi:deploy -d deploy_pre_steps_portal_common -u Portal_C1_Common_Scratch

Push Code

  • sfdx force:source:push -u Portal_C1_Common_Scratch

Open Scratch Org

  • sfdx force:org:open -u Portal_C1_Common_Scratch

Enable communities (Manual Steps)

  1. In Setup > Communities, enable communities and then set prefix to "Portal-C1-Test-JW0001", where "JW" are your initials
  2. Click "New Community" > Pick "Build Your Own" > Get Started, use "test" for both the Name and URL
  3. Once Community is created, in Administration > Emails: turn off "Send welcome email"; in Settings: Activate Community
  4. Go to Communities, select Builder > Publish. Test community. Make sure you can browse to community.

Deploy Remaining Stuff

  1. sfdx force:mdapi:deploy -d deploy_post_steps -u Portal_C1_Common_Scratch
  2. sfdx force:mdapi:deploy -d deploy_permission_set -u Portal_C1_Common_Scratch
  3. sfdx force:user:permset:assign --permsetname DX_Developer -u Portal_C1_Common_Scratch
  4. sfdx force:data:tree:import --sobjecttreefiles ./data_files/PortalData.json -u Portal_C1_Common_Scratch
  5. sfdx force:data:bulk:upsert -s ForgeRock_Settings__c -f ./data_files/ForgeRock_Settings__c.csv -i Id

Manually Load Additional Data

  1. Load the site content for core and client communities (files in ./communities_content/):
  • Setup > all communities > Workspaces > Administration > Pages > Go to Site.com Studio: click the gear icon in the top right corner:

    • Select "Overwrite This Site": Browse to the appropriate .site file, click Overwrite, then Publish Changes
  • Do this for both communities. Make sure you can browse to community.

Code Management

Create New Branch

Scrum teams should create a new branch for any development work.

  • Create a new branch from master - use Eclipse or other IDE to create a branch
  • Branch naming convention: TeamNameReleaseDate - ReleaseDate in YYYYMMDD format

Make Changes

If you need to add a field, create a Lightning component, change Apex classes, etc., you can make changes in the scratch org using the Salesforce interface and Developer Console. You can also create components, classes, etc., using the IDE or command line.

Pull/Push Code from/to Scratch Org

If you make changes in the scratch org, you will need to "pull" the code from the org:

  • sfdx force:source:pull

If you make changes using an IDE, you will have to "push" those changes to the scratch org:

  • sfdx force:source:push

Delete a Scratch Org

  • sfdx force:org:delete -u Portal_C1_Common_Scratch

Commit to Source Control

Follow the standard git commit process:

  1. git status
  2. git add .
  3. git commit -m ""
  4. git push

Common Lightning/Apex Commands

Create New Lightning Component

  • sfdx force:lightning:component:create -n Unum_Portal_Common_V1_AS213_Component

Create Apex

  • sfdx force:apex:class:create -n MyClass

Additional Lightning Commands

  1. force Namespace Commands

Deployment

DEV

  1. Connect to the Dev Hub: sfdx force:auth:web:login -r https://test.salesforce.com -a Dev

  2. Create a folder in root of CS_Unum.Portal.Common: mkdir mdapi_deploy_dev

    • Copy source into folder: sfdx force:source:convert -d mdapi_deploy_dev/
    • Delete items from folders not deploying; update package.xml with items only being deployed
    • Deploy to the Dev environment: sfdx force:mdapi:deploy -d mdapi_deploy_dev/ -u [YOUR_SF_DEV_USERNAME]
  3. Log into the Salesforce Dev environment, check Deployment Status.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment