Newer Version Available
Create Aura Components Using the Salesforce CLI
- Salesforce CLI
- Visual Studio Code or another code editor
- Salesforce Extension Pack, if using Visual Studio Code
- A Developer Edition org
To install the Salesforce CLI and verify the installation, follow the instructions at Salesforce DX Setup Guide.
Use your favorite code editor with the Salesforce CLI. We recommend using Visual Studio Code because its Salesforce Extension Pack provides powerful features for working with the Salesforce CLI, the Lightning Component framework, Apex, and Visualforce.
- Visual Studio Code (VS Code)
- Salesforce Extension Pack for Visual Studio Code
To create and deploy an Aura Component to your org:
-
Create a Salesforce DX project.
- In Visual Studio code, open the Command Palette by pressing Ctrl+Shift+P on Windows or Cmd+Shift+P on macOS.
- Type SFDX and then select SFDX: Create Project.
- Enter HelloAuraComponent and then press Enter. Select a folder to store the project.
-
Click Create Project. You should see something
like this in your Visual Studio Code workspace.
-
Create an Aura component.
- Open the Command Palette and select SFDX: Create Lightning Component.
- Enter a name for your component, such as myComponent. Press Enter.
-
Enter the directory for your component or press
Enter to accept the default. The default
directory is force-app/main/default/aura. You
should see a similar directory like this.
-
Open myComponent.cmp and replace its
content.
1<aura:component> 2 Hello World! 3</aura:component>
-
Authenticate to your org. This step uses a Dev Hub org.
- Open the Command Palette and select SFDX: Authorize a Dev Hub Org. A browser window opens with a Salesforce login page.
-
Log in to your org. If prompted to allow access, click
Allow.
After you authenticate in the browser, the CLI remembers your credentials. The success message looks like this.
115:53:54.247 sfdx force:auth:web:login --setdefaultdevhubusername 2Successfully authorized username@my.org with org ID 00D1a0000000000000 3You may now close the browser 415:55:22.961 sfdx force:auth:web:login --setdefaultdevhubusername ended with exit code 0If the authentication fails, follow the troubleshooting guide at Salesforce DX Setup Guide.
-
Deploy your files.
-
In the Visual Studio Code terminal, run this command.
1sfdx force:source:deploy -p force-app -u username@my.orgThe success message looks like this.1=== Deployed Source 2FULL NAME TYPE PROJECT PATH 3──────────────────────────────────── ──────────────────── ──────────────────────────────────────────────────────────────── 4myComponent/myComponent.auradoc AuraDefinitionBundle force-app/main/default/aura/myComponent/myComponent.auradoc 5myComponent/myComponent.cmp AuraDefinitionBundle force-app/main/default/aura/myComponent/myComponent.cmp 6myComponent/myComponent.cmp AuraDefinitionBundle force-app/main/default/aura/myComponent/myComponent.cmp-meta.xml 7myComponent/myComponent.css AuraDefinitionBundle force-app/main/default/aura/myComponent/myComponent.css 8myComponent/myComponent.design AuraDefinitionBundle force-app/main/default/aura/myComponent/myComponent.design 9myComponent/myComponent.svg AuraDefinitionBundle force-app/main/default/aura/myComponent/myComponent.svg 10myComponent/myComponentController.js AuraDefinitionBundle force-app/main/default/aura/myComponent/myComponentController.js 11myComponent/myComponentHelper.js AuraDefinitionBundle force-app/main/default/aura/myComponent/myComponentHelper.js 12myComponent/myComponentRenderer.js AuraDefinitionBundle force-app/main/default/aura/myComponent/myComponentRenderer.js
-
In the Visual Studio Code terminal, run this command.
1sfdx force:source:retrieve -p force-app -u username@my.org