username: rodriggj@provar.com
password: T@****!
Install Visual Studio Code
Install Salesforce CLI
[ ] Installation instruction for your platform can be found here
[ ] In a terminal session validate installation by running
sfdx
sfdx plugins --core
Install Extensions in Visual Studio Code
NOTE: In Visual Studio Code to initiate an integrated terminal session on a Mac type
Ctrl + ~
. When the terminal session comes up validate that you can execute commands likesfdx
. If you CANNOT you may need to configure yourENV PATH
to point to thesfdx
download binaries.
Navigate to your developer org login screen which you can access from login.salesforce.com
, enter login credentials.
When the page redirects to the Setup screen. In the left-nav bar at the top is a Search function. Enter domains
. Select My Domain
from the returned list of values.
You must enter a globally unique domain value. Enter a value unique to you and Check Availability. Keep Trying till you find one.
I entered
line-blend-skis
as my unique string, which was available and with some additional input from Salesforce my new domain becameline-blend-skis-dev-ed.my.salesforce.com
You will need to wait for Salesforce to Provision you new Domain
. You will know that it is provisioned with the receipt of an email message from Salesforce. When you do receive this notice you can complete the last step which is to Deploy your new Domain to Users
. This will be a button that will display and you can click this button.
You will be redirected to the login screen login.salesforce.com
. Enter your credentials and you should be logged in to the Org with the URL as the new domain.
Project
and DevHub
Developer Documentationsfdx force:project:create -n "learning_org"
Note:
-n
is the name flag
Dev Hub
. To do this we can execute the following commandsfdx force:auth:web:login -a rodrizzledevhub -d
Note:
-a
flag is an alias flag, where you will assign a name to the DevHub. The-d
flag will set this DevHub as default. When you execute this command you will be redirected to the front-end SFDC UI. Here you will be asked for your login credentials, possibly a verification code, and verification that the user is allowed to access the Salesforce application via the CLI tooling, SFDX.
config/project-scratch-def.json
in your code editorfeatures
node in the json file, add another node (aka key:value pair) like this..."hasSampleData": true,
You do not have access ...
error, make sure that before you execute any commands using the CLI to create a scratch org, that you enable the ability to do so in the Salesforce UI.
Setup
Dev Hub
Enable Dev Hub
option is Disabled, you need to enable this functionalityScratch Orgs
. To create a Scratch Org
we will execute the following command. sfdx force:org:create -a lwcScratchOrg -d 30 -f config/project-scratch-def.json -s
Note: Explanation of the above command...
In this command the
-a
flag still stands for alias so we assign this scratch org a name of _lwsScratchOrg.The
-d
flag DOES NOT meandefault
in this case, but ratherdays
orduration
(in days). The SFDC platform allows a scratch org to exist from 1 - 30 days, after the 30 day limit the scratch org will be deleted. So in this case we are setting a maximum duration of 30 days.We use the
-f
flag to specify the file that is the configuration specification for our Scratch Org. This was the project-scratch-def.json file. To refer to this file we need to specify the path to this file which, if we are in the root directory will simply be config/project-scratch-def.json.Finally, we need to tell Salesforce that we want to use the same user
rodriggj@provar.com
that set up the org, so we use the-s
flag to specify same default username.A successful result will render an image similar to the following, with a Scratch Org ID, and UserName defined.
Scratch Org
has been created you can open the Scratch Org
from the terminal with the following command. This command will redirect you back to the salesforce UI where you can verify you have a new Org
by the domain in the URL will be new -- this is the domain of the Scratch Org
.sfdx force:org:open
NOTE: If you want to see what all the available commands in are from the CLI you can see the help documenation by typing
sfdx commands
in the terminal.
lwc
directory within the folder structure of the Project
you created.cd learning_org/force-app/main/default/lwc
lwc
component with the CLIsfdx force:lightning:component:create --type lwc -n helloWorld
sfdx force:org:open
In the Setup
screen, use the Search
filter and query for App Manager
. Click New Lightning App
and advance through the wizard. You Do Not need to add any Navigation Items. Also, when presented with the option to add User Profiles you Only Need System Administrator
role for now.
Now that you've created the Application, you will now need to add Pages to the application. By default your application will not have any. To do this go back to Setup and in the Search bar type Lightning App Builder
Navigate through the wizard.
lwc > helloWorld > helloWorld.html
file. In this file between the <template> </template>
tags copy/paste the following code, and save and close this file. <template>
<div style="border: 1px solid red;">
<p>Hello World</p>
<p>This is the hellow world component that we built in our Project Structure.</p>
<button>Push Me!</button>
</div>
</template>
helloWorld.js-meta-xml
file. Open this file and copy / paste the following code:<!-- Was -->
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>51.0</apiVersion>
<isExposed>false</isExposed>
</LightningComponentBundle>
<!-- Change to -->
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>51.0</apiVersion>
<isExposed>true</isExposed>
<targets>
<target>lightning__AppPage</target>
</targets>
</LightningComponentBundle>
push
this to Salesforce so it becomes available for salesforce to use. In the terminal, enter the following command: sfdx force:source:push
Note: Once you've pushed the changes to the Salesforce Scratch Org, you should see the
Custom Component
become available to you for use in the UI. If the UI was already opened prior to thesfdx force:source:push
command you may have to click the Refresh button for the component to appear.
Foobar Application
and there it is ... your first LWC deployed. data binding
. helloWorld.js
file. In here we will set some local properties to our helloWorld
class. // Was
import { LightningElement } from 'lwc';
export default class HelloWorld extends LightningElement {}
// Change to
import { LightningElement } from 'lwc';
export default class HelloWorld extends LightningElement {
fullName = "Gabe Rodriguez"
message = "I hope you have a wonderful day."
}
helloWord.html
file and implment the data binding<template>
<div style="border: 1px solid red;">
<p>Hello {fullName}</p>
<p>This is the hellow world component that we built in our Project Structure.</p>
<p>{message}</p>
<button>Push Me!</button>
</div>
</template>
javascript
file to the html
file, but the input is still hardcoded. So how do we allow the user to input data in real-time and the html input update on the screen? To do this you need Two-Way Data Binding. method
. A method is simply code that provides some behavior to your application. In this case we want to change the screen input so we need a changeHandler method. In the method we will ask for some initiating activity called an event. The event in this case is the typing of new input into the screen. When we receive this event we will tell the html to update the screen value on the UI. We will display a new message this time, where we are asking the user to input a course title. So in the javascript we need to add a title property to the class, and use it to store the value the user inputs. Modify your helloWorld.js
file with the following code:
// Was
import { LightningElement } from 'lwc';
export default class HelloWorld extends LightningElement {
fullName = "Gabe Rodriguez"
message = "I hope you have a wonderful day."
}
// Change to...
import { LightningElement } from 'lwc';
export default class HelloWorld extends LightningElement {
fullName = "Gabe Rodriguez"
message = "I hope you have a wonderful day."
title = "aura"
changeHandler(event){
this.title = event.target.value
}
}
helloWorld.html
file. Here we need to modify the presentation of the UI with 2 new items. The first is an input field allowing the user to type in some new title of a course. The second is the sentence (string) that will display the input dynamically. In the file enter the following code...<template>
<div style="border: 1px solid red;">
<label>Course Title</label><input type=text onkeyup={changeHandler}/>
<hr>
<div>Hello, {fullName} attending the {title} course.</div>
</div>
</template>
Note: The
fullName
and the new propertytitle
are in the interpolation syntax{ }
, and will be read from the javascriptchangeHandler
method or the properties in the Javascript class and passed to thehtml
.
sfdx force:source:push
Card
component. Open a browser and search for Salesforce Lightning Component Library
Once the Library opens, in the Quick Find Search bar, type Card
. You will see a response in the left-nav-bar that says Components > lightning > card, select this element.
The main portion of the page will render details of the Card
component. In this component at the bottom you will see code, in the Lighting Mini Playground. Copy the code between the <template></template>
tags, which should look like the code below.
<lightning-card title="Hello">
<lightning-button label="New" slot="actions"></lightning-button>
<p class="slds-p-horizontal_small">Card Body (custom component)</p>
<p slot="footer">Card Footer</p>
</lightning-card>
helloWorld.html
file, and lets use this code with some modifications. We don't want the text that we saw in the Lighting Web Component library because it won't match our properties and we'll have to reconfigure our Two-Way-Data Binding. So let's do the following:
<lightning-card> </lightning-card>
tags should be what we previously had with our input field and title, so copy your previous code and paste it between these 2 tags.<lightning-card title="Hello">
change this to <lightning-card title="LWC Reuse Example">
<template>
<lightning-card title="LWC Reuse Example">
<label>Course Title: </label><input type=text onkeyup={changeHandler}/>
<hr>
<div>Hello, {fullName} attending the {title} course.</div>
</lightning-card>
</template>
sfdx force:source:push
CSS
styling, which can be found here Salesforce Design System. Again we can query for margin
. There are multiple margin options, but we want the margin to be Around our entire card, so if you scroll down you will see Around, and we'll select the <div class="slds-m-around_x-small"></div>
tag. We can go back and add this to our component like this and redeploy. <template>
<lightning-card title="LWC Reuse Example">
<div class="slds-m-around_x-small">
<label>Course Title: </label><input type=text onkeyup={changeHandler}/>
<hr>
<div>Hello, {fullName} attending the {title} course.</div>
</div>
</lightning-card>
</template>
sfdx force:source:push
input
to add to you component. <template>
<lightning-card title="LWC Reuse Example">
<div class="slds-m-around_x-small">
<!-- <label>Course Title: </label><input type=text onkeyup={changeHandler}/> -->
<lightning-input type="text" label="Enter some text" placeholder="type here..." onkeyup={changeHandler} required></lightning-input>
<hr>
<div>Hello, {fullName} attending the {title} course.</div>
</div>
</lightning-card>
</template>
Here you see this one has embedded validation indicating that a mandatory field is now empty.
When you populate the field the error goes away and the text renders just like before.