3

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

2

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>
  • Hi Mohith, thanks for a real quick response. I tried to replicate your example but i am getting an empty array for the raw response. Please find the image below. Am i missing something. i.imgur.com/8vWgDgh.png – user477 Jun 22 '15 at 19:22
  • @sangram Looks like you dont have recordtypes for accounts assigned to admin profile .You need recordtypes for account to check. – Mohith Shrivastava Jun 22 '15 at 19:28
  • Thanks Mohith, well i have a custom object for which there are a few record types. And i'm getting the same null array response. Both in workbench as well as apigee console. Is there any other way, like some metadata api usage or something similar. – user477 Jun 22 '15 at 19:36
  • @sangram I cant spoon feed .From my answer its clear you need to add your object name in the URL '/services/data/v33.0/sobjects/ObjectName/describe/layouts/' – Mohith Shrivastava Jun 22 '15 at 19:52
2

I finally figured it out via Ajax Toolkit. Thanks for all the answers but using Ajax Toolkit, one could perform a SOAP call and get all metadata information of an object, e.g. The specific piclist values for each record type.


(function(){
var result = sforce.connection.describeLayout('Liability_Information__c');
console.log(result); //parse this object to find picklist values for each record type
}());

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy