Newer Version Available

This content describes an older version of this product. View Latest

Run Through the Dreamhouse Example

The quickest way to get going with sf is to clone the dreamhouse-lwc GitHub repo. Use its configuration files and Salesforce application to try out some of the new sf commands and see how they work with sfdx. In this example, we use sf commands when possible, but if sf doesn’t provide certain functionality, we use the appropriate sfdx command instead.
  1. Open a terminal or command prompt window, and clone the dreamhouse-lwc GitHub sample repo using HTTPS or SSH.
    1git clone https://github.com/trailheadapps/dreamhouse-lwc.git
    2 --or--
    3 git clone git@github.com:trailheadapps/dreamhouse-lwc.git
  2. Change to the dreamhouse-lwc project directory.
    1cd dreamhouse-lwc
  3. Log in to your Dev Hub org to authorize it to create scratch orgs. Set it as your default Dev Hub and assign it an alias.
    1sf login org --set-default-dev-hub --alias DevHub

    Enter your Dev Hub org credentials in the browser that opens. After you log in successfully, you can close the browser.

  4. Create a scratch org using the config/project-scratch-def.json file, set it as your default, and assign it an alias.
    1sf env create scratch --definition-file config/project-scratch-def.json --set-default --alias my-scratch-org

    The command uses the default Dev Hub you set with the sf login command in a previous step.

  5. View the environments (in this case, orgs) that you've either created or logged into.
    1sf env list

    The first table displays the Dev Hub you logged into and the second table displays the scratch org you created. The right-most Config column in both tables indicates the default scratch org and Dev Hub org with the target-org and target-dev-hub configuration variables, respectively. The left-most Aliases column displays the aliases you assigned each org. Here’s some sample output.

    1Salesforce Orgs
    2=====================================================================================================
    3| Aliases Username                Org ID   Instance Url                      Auth Method Config  
    4| ------- ----------------------  ------   --------------------------------  ----------- -------------
    5|         user@unicorn-qv0giu.com 00D5e123 https://unicorn.my.salesforce.com web     
    6| DevHub  user@moose-qycot1.com   00D3h456 https://moose.my.salesforce.com   web         target-dev-hub   
    7
    8Scratch Orgs
    9========================================================================================================
    10| Aliases        Username             Org ID    Instance Url                      Auth Method Config  
    11  -------------  -------------------- --------- --------------------------------- ----------  ----------
    12| my-scratch-org test-0xo@example.com 00D1D0789 https://ability.my.salesforce.com web         target-org
  6. Deploy the Dreamforce app, whose source is in the force-app directory, to the scratch org.
    1sf deploy metadata --source-dir force-app
  7. Assign the dreamhouse permission set to the default user.
    1sfdx force:user:permset:assign -n dreamhouse
  8. Import sample data into the scratch org.
    1sfdx force:data:tree:import -p data/sample-data-plan.json
  9. Run Apex tests.
    1sfdx force:apex:test:run --resultformat human
  10. Open the scratch org and view the pushed metadata under Most Recently Used.
    1sf env open --target-env my-scratch-org
  11. Optionally, in the App Launcher, find and open Dreamhouse, just to make sure it deployed correctly.
  12. In the Salesforce UI, make a small cosmetic change to an item. For example, update a comment in the GeocodingServiceTest Apex class. This step is to later show how you retrieve metadata from an org.
  13. Back in the terminal or command window, retrieve the small change you made in the org to your project.
    1sf retrieve metadata --source-dir force-app

    Confirm that the small change you made in your org has been retrieved to your project by viewing the file force-app/main/default/classes/GeocodingServiceTest.cls.