Post 2 – Customizing Salesforce with Lightning Aura Components series

This will be the second of a series of posts I will be doing over the next few weeks. They will all lead up to the introduction of my new course titled, “Customizing Salesforce with Lightning Aura Components” from Pluralsight. This course is a total re-write of my most popular course, “Customizing Salesforce with Lightning Components: Getting Started“, which was released back in 2017. It will focus on using the new modern toolset that Salesforce offers as part of Salesforce DX.

Using an Interactive Development Environment (IDE)

For most modern web developers, their Interactive Development Environment (IDE) is a key to their success. For Salesforce developers, the best choice for an IDE is the Salesforce Extensions for Visual Studio Code.

If you have been a Salesforce developer for a while, then this may be new to you. You may be familiar with the Force.com IDE or Interactive Development Environment for Eclipse, which is incidentally not being supported by Salesforce any more.

Salesforce Extension Pack for VS Code
Salesforce Extension Pack for VS Code

Getting Setup with an IDE

To use the IDE, you will first need to install the latest version of Visual Studio Code. After this has been installed, you can open it up and click the extensions icon on the left toolbar.

Install Salesforce Extension Pack by clicking Extensions Icon
Install Salesforce Extension Pack by clicking Extensions Icon

You will also need to install the Salesforce Command Line Interface (CLI). This powerful command line interface allows you to do several things with your Salesforce org, such as:

  • Build and load source code (such as Aura components, Apex classes, Lightning Web Components and).
  • Export data from any Salesforce org and import it into your scratch org, which is a temporary org that has no data loaded by default.
  • Execute both Apex server-side and client-side JavaScript tests.

Once you get used to working with the Salesforce Extensions, you might want to check out the GitHub repo, since it is open source. You can get a lot of information about the extensions on the ReadMe page, as well and browse the useful Wiki and Issues tabs.

Understanding Salesforce DX (SFDX)

Salesforce DX represents a whole new set of developer tools. They represent a source-driven development model, which is considered more modern. It is all built around the CLI, which you just learned about. Most importantly it represents a new way of Salesforce development now known as “Packaging Development”.

Prior to packaging development, the only way developers had to deploy their code was to package it up in a Sandbox org and then deploy it to production. This made the salesforce org the “source of truth”, as developers like to call it. But the new model moves the source of truth from the org to a version control system, like Git.

Before you can create any Aura components in VS Code, you will need to do the following things first:

  1. Authorize a DevHub org using either the command palette or the sfdx force:auth:web:login CLI command.
  2. Create a Salesforce project using either the command palette or the sfdx force:project:create CLI command.
  3. Create a scratch org using either the command palette or the sfdx force:org:create CLI command.

Creating an Aura Component in Visual Studio (VS) Code

After you have authorized your DevHub and created a project, you can create an Aura component, by browsing to the Aura folder, right-clicking and selecting “SFDX: Create Lightning Component”.

Creating Aura Component in VS Code
Creating Aura Component in VS Code

Here is the markup code for a very basic component that can be used to update a users mobile phone number.

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes" access="global" >
	<lightning:card  title="Update Cell Number">
        <p class="slds-p-horizontal_small">
            <lightning:input aura:id="phone" type="tel" label="Cell Phone Number" name="phone" placeholder="343-343-3434" pattern="[0-9]{3}-[0-9]{3}-[0-9]{4}"/>
	    <lightning:button variant="brand" label="Submit" title="Submit" onclick="{! c.handleClick }" />        
        </p>
    </lightning:card>  
    
</aura:component>

And here is the JavaScript for the controller , in which the component will begin by only being able to create a windows alter that displays the number entered when the user clicks Submit.

handleClick : function (cmp, event, helper) {
        alert('phone: ' + cmp.find("phone").get("v.value"));
}

Exposing Aura Components to Lightning App Builder

The main thing you will need in order to expose your new component to Lightning App Builder is the following attributes on the required aura:component tag:

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes" access="global" >

But in order to make the component more usable to Admins that might build Lightning Pages using these components, it is a good idea to always include a design resource, such as this:

<design:component label="Update Cell Number">
    <design:Attribute name="placeholder" label="Placeholder" placeholder="343-343-3434" />
</design:component>

This will mean that you will also have to make a change to the component markup to add a new Aura attribute such as this:

<aura:attribute name="placeholder" type="String" default="343-343-3434"/>

And you will need to make another change to the lightning:input base lightning component, in which the expression syntax is used, such as this:

<lightning:input aura:id="phone" type="tel" label="Cell Phone Number" name="phone" placeholder="{!v.placeholder}" pattern="[0-9]{3}-[0-9]{3}-[0-9]{4}"/>

You can then save all your changes and push them to the scratch org using either the command palette or the sfdx force:source:push CLI command. You will also need to open the scratch org using either the command palette or the sfdx force:org:open CLI command.

One the org is open, to add the new component to the Sales home page, use App Launcher to go to the Sales app and then click the gear icon and select Edit Page.

Edit Page is used to access Lightning App Builder
Edit Page is used to access Lightning App Builder

You can then just scroll down the list of components until you get to the custom ones and drag the Update Cell Number one onto the design surface.

To finish you just need to save and activate the changes. You can then use the Back button to go back to the Sales home page and see the final component.

Update Cell Number Component, so far
Update Cell Number Component, so far

In the next post, this component will be improved on and tied to the Salesforce database.

Stay Tuned…

2 comments

Leave a Reply to Post 3 – Customizing Salesforce with Lightning Aura Components Series – Sara Has No Limits Cancel reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s