Salesforce development lifecycle
- johnsontitus
- May 14, 2020
- 4 min read
Updated: Jun 1, 2020
Source of truth is VCS
Setup the Salesforce DX:
Scratch Org:
You can spin up a new scratch org when you want to:
Start a new project.
Start a new feature branch.
Test a new feature.
Start automated testing.
Perform development tasks directly in an org.
Start from “scratch” with a fresh new org.
With its configuration file, you can configure the scratch org with different Salesforce editions and with just the features and settings you want. And you can share the scratch org configuration file with other team members. That way, you all have the same basic org in which to do your development.
Enable Dev Hub
You need a Dev Hub for you and your team to create and manage scratch orgs.
make any paid org your Dev Hub and grant access to developers.
Install the Command Line Interface (CLI)
Log In to the Dev Hub using the CLI command:
Authorize the Dev hub:
sfdx force:auth:web:login -d -a DevHub
to open the Dev Hub org to look at active scratch orgs
sfdx force:org:open -u DevHub
To log into other sandboxes using CLI to add them to its list:
sfdx force:auth:web:login -r https://test.salesforce.com -a FullSandbox sfdx force:auth:web:login -r https://test.salesforce.com -a DevSandbox
Use alias name to open orgs so that you dont have to use the lengthy username in scratch orgs:
sfdx force:org:open -u FullSandbox sfdx force:org:open -u MyScratchOrg sfdx force:limits:api:display -u DevSandbox
Create a Salesforce DX Project
Before you can build your first app, create a project and connect it to your source control repository.
Create a project called geolocation with a default manifest(package.xml) file
In a command window, navigate to where you want your project located.
sfdx force:project:create -n geolocation --manifest
to retrieve source (metadata that’s in source format) from an org
H:\SF\APEX\SF_Sample_DX\SF_DX_Project> sfdx force:source:retrieve -m ApexClass:AccessDataModel -u johnson.titus12@gmail.com
(retrieves the apex class AccessDataModel from Dev using the username)
To retrieve all custom objects
H:\SF\APEX\SF_Sample_DX\SF_DX_Project> sfdx force:source:retrieve -m CustomObject -u johnson.titus12@gmail.com
or
to retrieve from the local directory:
sfdx force:source:retrieve --sourcpath ..../force-app/main/default/classes/<*.cls>
to deploy source (metadata that’s in source format) to an org
sfdx force:source:deploy -m ApexClass:AccessDataModel -u johnson.titus12@gmail.com
sfdx force:source:deploy -m ApexPage:<visualforcepagename> -u johnson.titus12@gmail.com
Project folder structure is created with:
sfdx-project.json file that states its a Salesforce DX project.
config/project-scratch-def.json - determines the configuration of a scratch org, including which features and settings define its org shape. You can create a configuration file that your whole dev team can share.
Note: turn Lightning Experience caching on or off by setting the s1EncryptedStoragePref2 to false. During development, disabling caching saves you from repeatedly refreshing the page waiting for your Lightning component code changes to take effect.
force-app - the folder that contains the source for your project.
Note:
If you want to deploy onto Dev org without using Scratch org do the following:
convert our project to Metadata Api format
force:source:convert
or
sfdx force:source:convert -d ./metadata
Deploy to the Dev org:
sfdx force:mdapi:deploy -d <converted metadata api filename> -u <username>
Create a Scratch Org - change to project directory - sfdx force:org:create -s -f config/project-scratch-def.json -a GeoAppScratch
Push your local source and metadata to a scratch org. Note: Before you push source changes to the scratch org, or pull changes to your local project, you can view a list changes you’ve made locally or remotely(i.e on the scratch org). write code locally sfdx force:source:push run apex test sfdx force:apex:test: run --resultformat human open the scratch org and view the pushed metadata: sfdx force:org:open Assign the app to a tab Create a new permission set and assign the scratch user to the component object
Pull any changes you make in the scratch org back to your local project. We dont want the metadata profiles in the org to be pulled into the local project In your geolocation project directory, open the .forceignore file and add **/profiles as a new line to the file, then save the file. Your .forceignore file should look something like this: package.xml **/jsconfig.json **/.eslintrc.json **/profiles sfdx force:source:pull start with a fresh scratch org. A fresh scratch org ensures you’ve properly externalized all your source from the org. Create a new scratch org.sfdx force:org:create -f config/project-scratch-def.json -a GeoTestOrg Push your local source and metadata to the scratch org. sfdx force:source:push -u GeoTestOrg Assign your permission set. sfdx force:user:permset:assign -n Geolocation -u GeoTestOrg Load your sample data into the org. sfdx force:data:tree:import -f data/Account.json -u GeoTestOrg Open your org to see the pushed source and metadata. sfdx force:org:open -u GeoTestOrg
Sync this project with your source control repository.
add some sample data that’s more relevant to the app or package you’re building.
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'"
Export data to a new folder - data in your project directory, You can then commit that data to your source control repository, so you can reload it if you, or another developer, spins up a new scratch org.
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
or
to export data from Dev org to Scratch org:
sfdx force:data:tree:export -q "SELECT Id, Name, Phone, Description, Industry from Account" -u <username of the Dev org>
It will export the account records in account.json file in the current directory
In future, if you want to import data into your scratch org:
sfdx force:data:tree:import --sobjecttreefiles data/Account.json
or
sfdx force:data:tree:import -f Account.json -u<username of scratch org>
Note:
Whatever source control system you use, we recommend that you configure it to exclude the .sfdx folder from being added to the repository. This folder holds temporary information for your scratch orgs, so you don’t have to save it for posterity . In Git, you would add it to the .gitignore file.
source code - https://github.com/JohnsonTitus/auraAccountLocator.git
Convert an existing app to source format. Source format is the decomposed file structure for the Salesforce DX project.
Create the project and scratch org
Install the DreamInvest unmanaged package
Create the appropriate permissions set
Extract the DreamInvest package source into your project sfdx force:mdapi:retrieve -s -r ./mdapipackage -p DreamInvest -u TempUnmanaged -w 10 (source for the app in metadata format.)
Convert the source, push it into a new scratch org and verify your work (convert metadata format to source format) sfdx force:mdapi:convert -r mdapipackage/ All the converted source is now in the force-app folder. Why that folder? Because that’s the default specified in sfdx-project.json. to convert source to metadata sfdx force:source:convert -d mdapioutput/
Deploy the converted DreamInvest app using the Metadata API
Register your testing environment
Convert from source format to metadata format and deploy the DreamInvest app to your Trailhead Playground
To learn more - https://trailhead.salesforce.com/content/learn/modules/sfdx_app_dev/sfdx_app_dev_deploy
Note: to propagate deletion of custom object from a developer sandbox to prod use ANT


Comments