[SalesForce] Lightning – retrieve picklist values available for RecordType

How can I show only picklist values allowed for a specific Record Type?

For example:

Case.Status values are "Pending", "Open", "Closed"

  • Case RecordType1 only allows the Pending value
  • Case RecordType2 allows Open and Closed values

I'm developing a Lightning component in a Visualforce Page but I haven't found a convenient lightning-way to do this.
I'm looking for a stable solution, that allows me to remove the component from the VF page at any time.

In Visualforce I used to invoke the describeLayout API offered with connection.js and it worked well:

sforce.connection.describeLayout(
    selectedObjectType,
    new Array(recordTypeId), {
       onSuccess: handleDescribeLayoutSuccess,
       onFailure: handleDescribeLayoutFailure
    }
); 

So I tried to import connection.js in my Lightning component using ltng:require and retrieving the SessionId with a server-side action.
It works well with Locker Service disabled, but when it is enabled the describeLayout response always enter in the onFailure callback.

The data provided to the onFailure function shows the layout describe in XML, but it is treated as an error.

The response data is below (just skipped part of the inner describe):

Remote invocation failed, due to: 
<?xml version="1.0" encoding="UTF-8"?>
  <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="urn:partner.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Header>
      <LimitInfoHeader><limitInfo><current>2</current><limit>15000</limit><type>API REQUESTS</type></limitInfo>
      </LimitInfoHeader>
    </soapenv:Header>
    <soapenv:Body>
       <describeLayoutResponse>
         <result><-- correct layout describe, skipped for readability --></result>    
       </describeLayoutResponse>
    </soapenv:Body>
  </soapenv:Envelope> status code: 

Best Answer

You can now use the UI API from your lightning component's apex controller to retrieve this information. It's not ideal because you have to use an API call into your own org, but at least it is now possible.

See the salesforce documentation on the UI API here.

The callout would be /ui-api/object-info/{objectApiName}/picklist-values/{recordTypeId}/{fieldApiName}. This retrieves picklist values based on the record type ID you pass it.