We have built a Lightning Component for displaying OrderLines__c (custom object). Since we need to utilize picklist values we could not use the lightning:datatable. I found a great guide on sfdcmonkey.com (http://sfdcmonkey.com/2017/12/08/lightning-data-table-inline-editing/) of how to build my own data table with inline edit supporting picklists.
The problem is that our OrderLines__c object is also utilizing Record Types. However there does not seem to be a straight forward way to get the picklist values for a specific Record Type in Apex. I can use the User Interface API (https://developer.salesforce.com/docs/atlas.en-us.uiapi.meta/uiapi/ui_api_resources_picklist_values.htm).
But since every OrderLine__c is its own component. This mean there is going to be one call for every line. Which is going to end up in a lot of API calls.
So my question is:
What is the best approach to handle this?
I have been thinking about using Apex Scheduler and update a static resource with the current values. However I am hoping there is a better solution.
Best Answer
You can use a helper object to share data across multiple components. This is the principle behind the lightning:empApi component; it shares a connection across multiple components to multiplex a streaming API connection. I'm not going to write a full, production-ready solution for this, but I have written a demo that should get you started.
This code, of course, doesn't have any error handling, and should not be considered production-ready, but it should demonstrate enough technique to get you to a viable solution. Once you have the describe info, you'll have the "validFor" bitmap, which you'll need to parse yourself. See this answer for how to parse this bitmap.