Lightning Picklist By Record Type

The Backstory

Enforcing record type visibility and field dependencies for picklist fields in a fully custom development context has been a struggle for a while now. With the addition of lightning:recordEditForm in Spring ’18 release, that struggle was diminished sizably. There are still, though, times when lightning:recordEditForm simply can’t be used for one reason or another. For example, building a form that is a mashup of several different objects or using a visual flow.

The typical way I have seen this implemented is to  store record type and dependency information in separate objects and point the code or flows to that object to determine which picklist values should be displayed to the end user. It’s a great idea but a beast to maintain, especially for companies who frequently update picklist values.

The Solution

Several releases ago Salesforce introduced a new endpoint to the Salesforce User Interface API, “picklist-values/”, that returns visibility data for both record types and field dependencies. The big issue that has made this solution hard to build out is the fact that lightning components cannot access the user’s Session ID; which results in authentication issues with the integration. Raj Vataki wrote an awesome blog on this very issue here.

This package utilizes the technique that Raj’s Lightning blog covers and wraps up all the code into reusable components that you can plop anywhere you would like in your custom development project. This solution does take a little bit of time to configure at the beginning (5-10 minutes), but it is definitely worth it. I have included step-by-step instructions on setting everything up in the GitHub README.

The 2 main components in this package are “RTPL_RecordTypeSelectList” and “RTPL_FlowRecordTypeSelectList”. “RTPL_RecordTypeSelectList” is designed for using in lightning components by a lightning developer. “RTPL_FlowRecordTypeSelectList” is a lightning component that can be used in visual flows by admins. The flow component can have up to 5 levels of field dependencies.

For a completely custom UI, developers can use the “RTPL_RecordTypePicklistValues” component to simply gather the information about picklists and display it in another way.

Download

The installation instructions, documentation, and code can be found here on github.

Happy coding!

Get more coding help in Lightning with my Exception Handling Framework blog or reach out to us directly for any of our custom Salesforce Development Services.