This component allows easy implementation of adding picklist fields to lightning component and visual flows that enforce Record Type visibility as well as field dependencies.
NOTE: You must have at least 1 object with record types enabled to deploy this package to your organization.
- Create a Connected App
- Search for "App Manager" in setup
- Click "New Connected App"
- Fill out Basic Information
- Enable OAuth Settings
- Populate "Callback URL" with "https://login.salesforce.com" (we will change this later)
- Choose OAuth Scopes: Full Access (full), Perform requests on your behalf at any time (refresh_token, offline_access)
- Click "Save"
- Note the "Consumer Key" and "Consumer Secret" for step 2
- Create an Auth Provider
- Search for "Auth. Providers" in setup
- Click "New"
- Set "Provider Type" to "Salesforce"
- Populate "Name" and "URL Suffix" with whatever you would like
- Populate "Consumer Key" and "Consumer Secret" with values from step 1
- Click "Save"
- Copy the generated "Callback URL"
- Update Connected App callback URL
- Go back to the connected app from step 1
- Update the callback url with the callback url from the Auth Provider in step 2
- Create a Named Credential
- Search for "Named Credentials" in setup
- Click "New Named Credential"
- Fill out the Label with whatever name you would like to give it
- The "URL" should be the base url of your org. Format: https://[mydomain].my.salesforce.com, https://[instance].salesforce.com
- Set "Identity Type" to "Named Principal"
- Set "Authentication Protocol" to "OAuth 2.0"
- Set "Authentication Provider" to the Auth Provider you created in step 2
- Set "Scope" to "full refresh_token offline_access"
- Check the "Start Authentication Flow on Save"
- Under "Callout Options" select "Generate Authorization Header" and "Allow Merge Fields in HTTP Body"
- Click "Save"
- Salesforce will ask you to login. Login and grant access to the app when prompted.
- Update "RTPL Settings" custom setting
- Search for "Custom Settings" in setup
- Next to "RTPL Settings", click "Manage"
- Above "Default Organization Level Value" section, click "New"
- Set "Named Credential" to the API name of the Named Credential you created in step 4
- Set "Api Version" to the api version of the salesforce User Interface API you would like to use. (Currently 44.0)
- Click "Save"
To add to visual flow, add "RTPL_FlowRecordTypeSelectList" to a screen element. This flow component supports up to 4 dependent picklists. There are 5 attributes you can set for each field:
- Name: The field API name
- Label: The field label
- Value: The selected value of the field
- Size: The width size of the picklist field (divided into 12). ie: "6" would be 50% width, "12" would be 100% width
- Required: Determines if the field is required
There are 3 more properties that apply to the whole component:
- addSelectOpt: Determines if the default picklist option is "--Select--" (true) or the first picklist value (false)
- sobject: SObject API Name that holds the field
- recordTypeName: Record Type label. Required if recordTypeId is not supplied
- recordTypeId: Record Type Id. Required if recordTypeName is not supplied
To add to a lightning component, use "c:RTPL_RecordTypeSelectList". This component inherits all of the properties of lightning:select. Here are the additional attributes:
- addSelectOpt: Determines if the default picklist option is "--Select--" (true) or the first picklist value (false)
- sobject: SObject API Name that holds the field. Required if sobjectField is not supplied
- recordTypeName: Record Type label. Required if recordTypeId is not supplied
- recordTypeId: Record Type Id. Required if recordTypeName is not supplied
- sobjectField: Fully qualified API name. If provided, sobject and fieldName are not used
- fieldName: The field API name
There is 1 method, getSelected(), that will return the value of the field if the "value" attribute is not set. Usage:
var selectedValue = component.find('mypicklist').getSelected();
If you want to display the picklist values based on record type and dependencies in a different way, use the component "RTPL_RecordTypePicklistValues." This component will retrieve the picklist properties and return the information. Here are the attributes:
- sobject: SObject API Name that holds the field. Required if sobjectField is not supplied
- recordTypeId: Record Type Id. Required if recordTypeName is not supplied
- recordTypeName: Record Type label. Required if recordTypeId is not supplied
- recordTypeProperties: The picklist properties returned by the User Interface API. Returns instance of RTPL_PicklistValues wrapper.
- sobjectField: Fully qualified API name. If provided, sobject and fieldName are not used
- fieldName: The field API name