Sample Components for Lightning Component Actions
This repository contains sample components to help you build Lightning component actions, which can be used to replace JavaScript buttons used in Salesforce Classic. These components cover the following use cases that are common in JavaScript buttons:
- Dialogues
- Conditional URL
- Mass Updates
Getting Started
Using Salesforce DX:
-
Mac or Linux
git clone https://github.com/developerforce/LEXComponentsBundle
cd LEXComponentsBundle
./install.sh
-
Windows
git clone https://github.com/developerforce/LEXComponentsBundle
cd LEXComponentsBundle
install.cmd
Not using Salesforce DX: Install this unmanaged package to your Developer Edition or Sandbox org.
How to Choose a Component
- Look at your org to determine which JavaScript buttons are still in use and need to be converted.
- Pick a button that youโd like to replace.
- From the component list, pick one that closely matches what your JavaScript button is doing.
- Edit the component sample code to match your needs. Tip: Make a copy of the component's files and modify those instead.
- Test and deploy per the "Create and Test Your Lightning Component Action" section below.
Classes & Components
Components are listed by name. Details include the use case it applies to, the object it acts upon, its description, and the set of files that make up the component.
ย
Components that use Lightning Data Service begin with โldsโ. Components that donโt use Lightning Data Service have Apex classes associated with them.
- accountQuickContact
- Use case: Dialogues
- Object: Account
- Description: Opens a form to create a contact related to the account. This is similar to ldsAccountQuickContact, but in this case the data is sent to an Apex class instead.
- Files:
- accountQuickContact.cmp
- accountQuickContactController.js
- accountQuickContact.css
- AccountQuickContactController.cls
- TestAccountQuickContactController.cls
- ldsAccountQuickContact
- Use case: Dialogues
- Object: Account
- Description: An example of how Lightning Data Service works for creating a new record. Opens a form to create a contact related to the account. The data is sent to the server through the JavaScript controller, so no Apex class is needed.
- Files:
- ldsAccountQuickContact.cmp
- ldsAccountQuickContactController.js
- ldsAccountQuickContactLDS.css
- ldsDisplayRecord
- Use case: Dialogues
- Object: Account
- Description: An example of how Lightning Data Service works for displaying a record. A popup window opens showing data about the current record. In this case, neither a JavaScript controller nor an Apex controller are needed.
- Files:
- ldsDisplayRecord.cmp
- ldsDisplayRecordController.js
- ldsDisplayRecord.css
- ldsDeleteRecord
- Use case: Dialogues
- Object: Any
- Description: An example of how Lightning Data Service works for deleting a record. When the user executes the component, the JavaScript controller calls the server to delete the record, so no Apex class is needed.
- Files:
- ldsDeleteRecord.cmp
- ldsDeleteRecordController.js
- ldsDeleteRecord.css
- ldsSaveRecord
- Use case: Dialogues
- Object: Account
- Description: An example of how Lightning Data Service works for updating a record. A popup window opens with information about the record and an editing form. Upon saving, the record is updated. The JavaScript controller sends the updated data to the server, so no Apex class is needed.
- Files:
- ldsSaveRecord.cmp
- ldsSaveRecordController.js
- ldsSaveRecord.css
- massUpdateAccountCases
- Use case: Mass updates
- Object: Account
- Description: Updates all the cases related to the account. It changes the case priority to โLowโ, the status to โClosedโ and the description to โCase Closed.โ
- Files:
- massUpdateAccountCases.cmp
- massUpdateAccountCases.css
- MassUpdateAccountCasesController.js
- MassUpdateAccountCasesController.cls
- TestMassUpdateAccountCasesController.cls
- probonoOpportunity
- Use case: Dialogues
- Object: Opportunity
- Description: When executing this component in an opportunity, a popup window opens, asking for confirmation to convert the record to a pro-bono opportunity. If the user clicks โConfirmโ, the opportunity amount updates to $0 and the page refreshes.
- Files:
- probonoOpportunity.cmp
- probonoOpportunityController.js
- probonoOpportunity.css
- ProBonoOpportunityController.cls
- TestProBonoOpportunityController.cls
- redirectConditionalUrl
- Use case: Conditional URL
- Object: Account
- Description: Opens a popup window with two options: One opens the billing address in Google Maps, and the other opens the shipping address. This uses the record ID, sends it to the server, and retrieves the address data.
- Files:
- redirectConditionalUrl.cmp
- redirectConditionalUrlController.js
- recirectConditionalUrlHelper.js
- redirectConditionalUrl.css
- RedirectConditionalUrlController.cls
- TestRedirectConditionalUrlController.cls
- setOpportunityProbability
- Use case: Dialogues
- Object: Opportunity
- Description: Opens a popup window with three buttons. One button sets the probability of the opportunity to a High value (%80), another sets it to a medium value (%50), and the last to a low value (%20). The Javascript controller sends the record ID and the option selected to the Apex class.
- Files:
- setOpportunityProbability.cmp
- setOpportunityProbabilityController.js
- setOpportunityProbabilityHelper.js setOpportunityProbability.css
- setOpportunityProbabilityController.cls
- TestSetOpportunityProbabilityController.cls
Create and Test Your Lightning Component Action
- Make sure the Lightning components are installed in your org.
- In Setup, go to the Object Manager.
- Select the object that you want to add the action to.
- Click Buttons, Links & Actions, then click New Action.
- From the Action Type drop down list, select Lightning Component.
- Select the component you want to be called by the action.
- Enter a label for the action, then click Save.
- Add the action to the objectโs page layout.
a. Click Page Layouts.
b. Select the layout you want to add the action to.
c. If you havenโt already, click override the predefined actions in the Salesforce Mobile and Lightning Experience section of the layout.
d. In the palette, click the Mobile & Lightning Actions category, and then drag the action that you created to the Salesforce Mobile and Lightning Experience section.
e. Click Save. - Navigate to a record and give the quick action a try. Youโll likely find it in the page-level actions menu in the record highlights panel.
Let us know how you feel about the components. Post your feedback and questions to the Lightning Now! group in the Trailblazer Community with the hashtag #JS_Alternatives.