Let’s talk about a great new addition of the Spring’19 platform release to the
Salesforce Dev world, the Lightning Web Components framework, with our guest blogger Priscilla Sharon, Salesforce Business Solution Executive for DemandBlue.
DemandBlue is in the business of helping its customers maximize their Salesforce investment through predictable outcomes. As we thrive in an era of cloud-based Infrastructure, Platform and Software services, DemandBlue has pioneered “Service-as-a-Service” through a value-based On Demand Service model that drives bottom-line results. They foster innovation through “Continuous Engagement and On Demand Execution” that offers their customers Speed, Value and Success to achieve their current and future business objectives.
Salesforce DX Setup – Since inception, one of Salesforce’s core philosophies and the Big Idea has been to make building easy. Software should not be complex to install, set up, or customize. In fact, you shouldn’t have to even install software – it should be available to you at the click of a button – This declarative approach of Salesforce brought an end to complex and traditional methods of software development that even non-tech executives including business analysts and managers could slickly build line-of-business applications in a few clicks. However, while Salesforce was democratizing application development through clicks-not-code approach and ushering in the era of citizen programmer, there were other players who were strengthening their appeal to the traditional developer. With nuanced business requirements, modeling complex domains require more flexibility than clicks-not-code affords. Traditional methods of development weren’t dead after all.
As a result, Salesforce’s marketing and development efforts wanted to cater to the traditional developer with the introduction of Salesforce DX, a revolutionary product in the Salesforce App Cloud that allows users to develop and manage Salesforce apps throughout the entire platform in a more direct and efficient way. Used primarily by developers, Salesforce DX setup enables users to have true version control that allows them to have a better control over collaboration, auditing, disaster control and more.
Take a deeper dive into the comprehensive blog that gives you in-depth insights on how you can enable Salesforce DX environment and truly maximize its unique benefits.
Your 12 Step Salesforce DX Setup Guide
1. Set up your project
Salesforce DX introduces a new project structure for your org’s metadata (code and configuration), your org templates, your sample data, and all your team’s tests. Store these items in a version control system (VCS) to bring consistency to your team’s development processes. Retrieve the contents of your team’s repository when you’re ready to develop a new feature.
2. Salesforce DX Setup – Authorize the Developer Hub org for the project
During Salesforce DX setup, the Dev Hub org enables you to create, delete, and manage your Salesforce scratch orgs. After you set up your project on your local machine, you authorize with the Dev Hub org before you create a scratch org.
For this, you need to login to Dev/Sandbox Org from CLI
Run the force:auth:web:login CLI command on a directory where code for deploy to sfdx will be available.
sfdx force:auth:web:login –d
or
sfdx force:auth:web:login --setdefaultdevhubusername --setalias {ALIAS HERE}
NOTE: Login must be a valid login to your Dev/Sandbox Org and with Admin permissions.
3. Configure your local project
The project configuration file sfdx-project.json indicates that the directory is a Salesforce DX setup project. The configuration file contains project information and facilitates the authentication of scratch orgs and the creation of second-generation packages. It also tells the Salesforce CLI where to put files when syncing between the project and scratch org.
4. Configure your local project
After you create the scratch org definition file, you can easily spin up a scratch org and open it directly from the command line.
a) Create the scratch org
- Create a scratch org for development using a scratch org definition file. The scratch org definition defines the org edition, features, org preferences, and some other options.
- Specify scratch org definition values on the command line using key=value pairs
- Create a scratch org with an alias
- Create a scratch org for user acceptance testing or to test installations of packages
- Indicate that this scratch org is the default
- Specify the scratch org’s duration, which indicates when the scratch org expires (in days)
b) Open the org
- To open the scratch org: sfdx force:org:open -u <username/alias>
- To open the scratch org in Lightning Experience or open a Visualforce page, use the –path parameter: sfdx force:org:open –path lightning
c) Set default user
Copy the username and enter the following command to set the defaultusername:
sfdx force:config:set defaultusername={SET THIS TO NEW SCRATCH ORG’S USERNAME FROM THE ABOVE COMMAND}
d) Display All Orgs
Run the following command to confirm the default Dev Hub [marked with (D)] and Active Scratch Org [marked with (U)]:
sfdx force:org:list --all
5. Push the source from your project to the scratch org
To push changed source to your default scratch org:
sfdx force:source:push
To push changed source to a scratch org that’s not the default, you can indicate it by its username or alias:
sfdx force:source:push --targetusername [email protected]
sfdx force:source:push -u [email protected]
sfdx force:source:push -u MyGroovyScratchOrg
Selecting Files to Ignore During Push. It’s likely that you have some files that you don’t want to sync between the project and scratch org. You can have the push command ignore the files you indicate in .forceignore.
If Push Detects Warnings. If conflicts have been detected and you want to override them, here’s how you use the power of the force (overwrite) to push the source to a scratch org.
sfdx force:source:push –forceoverwrite
6. Salesforce DX Setup – Develop the app
a. Create Source Files from the CLI
To add source files from the Salesforce CLI, make sure that you are working in an appropriate directory.
Execute one of these commands.
apex:class:create
apex:trigger:create
lightning:app:create
lightning:component:create
lightning:event:create
lightning:interface:create
lightning:test:create
visualforce:component:create
visualforce:page:create
b. Edit Source Files
To edit a FlexiPage in your default browser—for example, to edit the Property_Record_Page source—execute this command.
sfdx force:source:open -f Property_Record_Page.flexipage-meta.xml
7. Pull the source to keep your project and scratch org in sync
After you do an initial push, Salesforce DX tracks the changes between your local file system and your scratch org. If you change your scratch org, you usually want to pull those changes to your local project to keep both in sync.
During development, you change files locally in your file system and change the scratch org using the builders and editors that Salesforce supplies. Usually, these changes don’t cause a conflict and involve unique files.
By default, only changed source is synced back to your project.
To pull changed source from the scratch org to the project:
sfdx force:source:pull
To pull source to the project if a conflict has been detected (read more):
sfdx force:source:pull –forceoverwrite
8. Salesforce DX Setup – Run tests
When you’re ready to test changes to your Salesforce app source code, you can run Apex tests from the Salesforce DX CLI. Apex tests are run in your scratch org.
You can also execute the CLI command for running Apex tests (force:apex:test:run) from within third-party continuous integration tools, such as Jenkins.
9. Export The Package.xml
Export package.xml file into the temporary directory. Type the commands below in the root folder of your Salesforce DX project:
sfdx force:mdapi:retrieve -r ./temp -u {TARGETUSERNAME} -k {SFDC PROJECT SOURCE LOCATION}\src\package.xml
10. Convert Source code to Salesforce DX
Convert the source code to the Salesforce Developer Experience project structure by running the following command:
sfdx force:mdapi:convert --rootdir temp --outputdir force-app
11. Track Changes Between the Project and Scratch Org
To view the status of local or remote files:
sfdx force:source:status
12. Salesforce DX Setup – Sync up
Sync the local version with the version deployed to Scratch Org for every change and test the changes on the Scratch Org by repeating the above steps. Once the testing is completed, we need to convert the source from Salesforce DX format to the Metadata API format. This is done by running the following command:
sfdx force:source:convert --outputdir {OUTPUT DIRECTORY HERE}
Copy the modified metadata files from this output location to the actual source location where the metadata files are downloaded from Dev/Sandbox Org to deploy the files to the server.
Leave a Reply