Skip to content

Lightning Web Component for Salesforce platform to allow a front-end selection of an Object Picklist value, having the values restricted by RecordType.

Notifications You must be signed in to change notification settings

foxysolutions/LWC-RecordtType-PicklistValue-Selector

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 

Repository files navigation

LWC RecordtType PicklistValue Selector

Lightning Web Component for Salesforce platform allowing front-end selection of an Object Picklist value, restricted by RecordType.

Challenge

In Salesforce Setup picklist values can be restricted per RecordType. Allowing distinction in business processes and guiding an end-user through that particulr process.

Unfortunately, those restrictions aren't always satisfied by Salesforce, e.g. in:

  • Dynamic Picklist Choices in Lightning Flows (SF Idea)

Solution

This Lightning Web Component retrieves and displays the picklist values which are valid for the provided RecordTypeId, independent of Object and Field.

The LWC is enabled for usage in a Flow Screens and Record Pages, but can be easily extended.

Lastly, the component includes a Validation message when no Picklist value was selected (to make it required). The Custom Label should be provided for this one.

Input:

Variable Description
objectName API name of Object
fieldName API name of Picklist Field on corresponding Object
recordTypeId Id of RecordType to restrict picklist values with (e.g. retrieve from current record, or retrieved to create new record )
isRequired Whether input field is required
errorMessage Error message to show in front-end when field required and not provided (e.g. retrieve from CustomLabel via Formula)

Output:

Variable Description
FieldValue Value returned

Screenshots

Configuration in Flow, configuring input and output variables.

  • The input in the screenshot is purely for documentation purposes to show the correct format;
  • NEVER put hard-coded (RecordType) Ids, always retrieve dynamically from a record {!sObj_Account.RecordTypeId} or from server {!Get_RetrieveRecordType.Id};
  • Likewise it is recommended to fetch a CustomLabel in Flow and provide that into the component.

Initial screen

Example of Industry picklist value for Business Accounts Example with validation

Restricted picklist values

Installation

The Component has been made available as unmanaged package (see links below) or can be retrieved from this repository and deployed to any Sandbox using SFDX CLI or an IDE.

About

Lightning Web Component for Salesforce platform to allow a front-end selection of an Object Picklist value, having the values restricted by RecordType.

Topics

Resources

Stars

Watchers

Forks