This document is intended for developers who are looking to get started with Salesforce DX. It will guide you through the process of setting up a development environment, creating and deploying a simple app, and will provide some tips along the way.
Before You Begin: Before you begin, there are a few things you’ll need:
A Salesforce organization. On the off chance that you don’t have one, pursue a Developer Edition organization. Note that this interaction won’t work with a Trailhead Playground or some other sort of preliminary organization.
Admittance to the Salesforce CLI.
In the event that you don’t have it introduced, adhere to the directions here.
An IDE or word processor of your decision. While you can utilize any word processor to code with Salesforce DX, we suggest utilizing either Visual Studio Code or Sublime Text 3.
The Force.com Migration Tool. This is a Java-based tool that allows you to deploy your code from one org to another. You can download it here.
Creating a Scratch Org:
A scratch org is a disposable Salesforce org that is created specifically for development purposes. It is configured exactly how you need it, and once you’re done developing, it can be deleted. This makes scratch orgs ideal for development, as they allow you to have complete control over the org and its configuration.
In order to create a scratch org, you’ll first need to generate a config file. This file will contain all of the necessary information about your scratch org, including its org type, features, and settings.
To generate a config file, open the terminal or command prompt and navigate to the project directory. Then, type the following command:
sfdx force:config:set defaultusername=<your_org_username>
Replace <your_org_username> with the username of your Salesforce org. Once you’ve done this, you can generate the config file by typing the following command:
sfdx force:config:create –definitionfile config/project-scratch-def.json –outputdir config
This will make a document called project-scratch-def.json in the config registry. Open this document and alter the “orgName” property to give your scratch organization a name. Then, save the record and close it.
Now that you have a config file, you can create the scratch org by typing the following command:
sfdx force:org:create –configfile config/project-scratch-def.json –setalias <your_org_alias> –setdefaultusername –wait 10
Replace <your_org_alias> with a unique alias for your scratch org. This will be used to identify the org when running commands from the Salesforce CLI.
You should now see a message indicating that your scratch org has been created successfully. To open the scratch org, type the following command:
sfdx force:org:open
This will open the organization in your default program. You might be provoked to sign in, after which you ought to see the Salesforce landing page.
Creating a Project:
Now that you have a scratch org, it’s time to create a project. A project is a set of files and directories that contain all of the source code for your app. In order to create a project, type the following command:
sfdx force:project:create –projectname <your_project_name> –manifest dir/<your_project_name>-scratch-def.json
Replace <your_project_name> with the name of your project, and replace <your_project_name>-scratch-def.json with the path to your scratch def file. This will create a directory called <your_project_name>, which will contain all of the files for your project.
Creating a Lightning Component:
Now that you have a project, it’s time to start coding! In this section, you’ll learn how to create a simple Lightning component.
Lightning components are reusable units of functionality that can be used in Salesforce apps. They are made up of HTML, CSS, and JavaScript, and can be used in both Lightning Experience and Visualforce pages.
To create a Lightning component, navigate to the force-app/main/default/components directory and create a new file called helloWorld.cmp. Then, open the file in your text editor and add the following code:
<aura:component>
<h1>Hello, world!</h1>
</aura:component>
This component contains a single HTML element, which will display the text “Hello, world!” on the page.
Conclusion:
In this article, you’ve learned how to create a scratch org and a project. You’ve also learned how to create a simple Lightning component. Now that you have the basics down, you’re ready to start building your own Salesforce apps!