Skip to content

Instantly share code, notes, and snippets.

@HemantShukla
Created March 12, 2016 20:28
Show Gist options
  • Save HemantShukla/bd09482256cc066b846a to your computer and use it in GitHub Desktop.
Save HemantShukla/bd09482256cc066b846a to your computer and use it in GitHub Desktop.
Describe layout for Picklist values based on Record type
<apex:page >
<apex:includescript value="/soap/ajax/20.0/connection.js"/>
<apex:includescript value="/soap/ajax/24.0/apex.js"/>
<apex:includeScript value="https://code.jquery.com/jquery-2.2.1.min.js" />
<script>
sforce.connection.sessionId = '{!$Api.Session_ID}';
var layout, recordTypeMap;
FinalResult = new Array();
layout = sforce.connection.describeLayout('Idea', new Array());
recordTypeMap = layout.recordTypeMappings;
//To remove the extra record type mapping for Master, not useful for usual case.
recordTypeMap.pop();
console.log('record type mappings:', recordTypeMap);
recordTypeMap.forEach(function(obj){
var recordTypeObj = {};
recordTypeObj.name = obj.name.substring(0,obj.name.indexOf(':'));
obj.picklistsForRecordType.forEach(function(pl){
recordTypeObj[pl.picklistName] = pl.picklistValues;
});
console.log(recordTypeObj);
FinalResult.push(recordTypeObj);
});
console.log('-----FinalResult', FinalResult);
</script>
</apex:page>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment