[SalesForce] Fetching picklist values based on record type

Is there any way to fetch picklist values based on a record type. I am wondering how salesforce does it. I am fetching list of record types via ForceTK, next i want to fetch picklist values based on a record type. ForceTK gives all information about an object metadata but i could not find any filtering based on record type.

I'm using the code below to fetch the metadata for my custom object.

var client = new forcetk.Client();
// Get the token from Visualforce
client.setSessionToken('{!$Api.Session_ID}');

client.describe('File__c', 
    function(response){
        console.log(response);                        
    }, 
    function(request, status, response){
      console.log(status);
    }
);

Regards,

Sangram

Best Answer

Not sure about ForceTK ,may be this is not implemented by library yet or safe harbour and I am not sure .

But normally through standard REST API we can implement this using below REST Service

/services/data/v33.0/sobjects/Account/describe/layouts/

For different object you can change Object name and versions

/vXX.X/sobjects/Object/describe/layouts/

I just checked my dev console and it does return values as expected .There is a recordtype mappings that can give you various picklists needed

enter image description here

I see you are using visualforce and hence if you use visualforce you can directly call this REST API from Visualforce using Jquery and it will not require any ForceTK(Although I love forceTk)

      <apex:page>
     <apex:includeScript value="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.2.min.js"/>
    <script>
     jQuery(document).ready(function($) {
     // Pull 10 Accounts via the REST API
      $.ajax('/services/data/v33.0/sobjects/Account/describe/layouts/',
    {
      beforeSend: function(xhr) {
        // Set the OAuth header from the session ID
        xhr.setRequestHeader('Authorization', 'Bearer {!$Api.Session_ID}');
      },
      success: function(response) {
        // We got 'em - append our records to the HTML list
        $.each(response.records, function(index, record) {
          $('#responselist').append('<li>'+record.recordTypeMappings+'</li>');
        });
      },
      error: function(jqXHR, textStatus, errorThrown) {
        // Oops - what went wrong?
        alert(jqXHR.status + ': ' + errorThrown);
      }
    }
  );
    });
  </script>
   <h1>Test REST API Without Proxy</h1>
     <p>Data:</p>
        <ul id="responselist">
     </ul>
  </apex:page>