title: Is there a way to retrieve Salesforce picklist values for record types using apex?
body: <p>I need to gather information about what picklist values are available for every record type. I know this can be achieved using either describeLayout or readMetadata API. But when I try to gather this info for a large custom object, troubles happen. The SalesForce API returns a record type with all available picklist values for it. </p>
  
  <pre><code>&lt;recordTypeMappings&gt;
      &lt;name&gt;Record1&lt;/name&gt;
      &lt;picklistsForRecordType&gt;
          &lt;picklistName&gt;Picklist1&lt;/picklistName&gt;
          &lt;picklistValues&gt;
              ...
          &lt;/picklistValues&gt;
      &lt;/picklistsForRecordType&gt;
      &lt;picklistsForRecordType&gt;
          &lt;picklistName&gt;Picklist2&lt;/picklistName&gt;
          &lt;picklistValues&gt;
              ...
          &lt;/picklistValues&gt;
      &lt;/picklistsForRecordType&gt;
  &lt;/recordTypeMappings&gt;
  &lt;recordTypeMappings&gt;
      &lt;name&gt;Record2&lt;/name&gt;
      &lt;picklistsForRecordType&gt;
          &lt;picklistName&gt;Picklist1&lt;/picklistName&gt;
          &lt;picklistValues&gt;
              ...
          &lt;/picklistValues&gt;
      &lt;/picklistsForRecordType&gt;
      &lt;picklistsForRecordType&gt;
          &lt;picklistName&gt;Picklist2&lt;/picklistName&gt;
          &lt;picklistValues&gt;
              ...
          &lt;/picklistValues&gt;
      &lt;/picklistsForRecordType&gt;
  &lt;/recordTypeMappings&gt;
  </code></pre>
  
  <p>It means if I have a large object (which includes 200 picklists and 100 record types), I will get 200*100=20,000 picklist records. It makes the API response extremely large, up to 80MB. And this is extremely inefficient, if a picklist values remain the same for all record types, they will still be included in each of them in API response.</p>
  
  <p>The idea is to get unique picklist values sets and then just include record ids with them, so the same picklist will not be duplicated with every record type. </p>
  
  <pre><code>&lt;recordTypeMappings&gt;
      &lt;name&gt;Record1, Record2&lt;/name&gt;
      &lt;picklistsForRecordType&gt;
          &lt;picklistName&gt;Picklist1&lt;/picklistName&gt;
          &lt;picklistValues&gt;
              ...Values which are the same for Record1 and Record2...
          &lt;/picklistValues&gt;
      &lt;/picklistsForRecordType&gt;
      &lt;picklistsForRecordType&gt;
          &lt;picklistName&gt;Picklist2&lt;/picklistName&gt;
          &lt;picklistValues&gt;
              ...Values which are the same for Record1 and Record2...
          &lt;/picklistValues&gt;
      &lt;/picklistsForRecordType&gt;
  &lt;/recordTypeMappings&gt;
  </code></pre>
  
  <p>This will reduce the response size. Is there a way to do that in Apex? I searched in API and was not able to find anything suitable. Apex seems a better solution, since all the processing will happen on the Salesforce side.</p>
  
  <p>Thanks for help.</p>