function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Faster pickListValues lookup

Does anyone have a fast/faster/fastest way to load the values of a specific picklist in a custom s control?
I am currently using:
var describeResult = sforce.connection.describeSObject("Case"); 
var fieldMap = []; 
var fields = describeResult.getArray("fields"); 

for(var i =0; i<fields.length; i++) 
fieldMap[fields[i].name] = fields[i]; 

var fldType = fieldMap["Product_or_Service__c"]; 
var selType = document.getElementById('prodService'); 
for(var j=0;j<fldType.picklistValues.length;j++) 
selType.options[j] = new Option(fldType.picklistValues[j].label, fldType.picklistValues[j].value); 
selType.options[j].selected = (fldType.picklistValues[j].defaultValue == true); 

which works, but its dog slow.  Anyone have a faster solution?  I always know exactly the name of the field I want the values for if that helps any.
I suppose calling a webservice enabled Apex function that performs the querying is out of the question?
Other than that I have no other tips. Sorry :(
Greg HGreg H
You'll have to test it out but this code is what I always use and it's not terribly slow:
//returns an array of picklist values for the passed table and field
function getPickVals(table,field) {
 var returnArray = new Array(); //return array holding all values
 var oTable = sforce.connection.describeSObject(table); //connect to table
 var oFields = oTable.fields; //look at fields on table
 for (var a=0; a<oFields.length; a++) { //loop through all the fields
  if (oFields[a].name==field) { //if the field is the requested one
   var oPicklistVals = oFields[a].picklistValues; //look at all the picklist values for field
   for (var b=0; b<oPicklistVals.length; b++) { //loop through all picklist values
    returnArray.push(oPicklistVals[b].value); //push all picklist options to return array
   break; //we found field and picklist values so exit loop
 return returnArray; //send back data

Simply assign a variable to the results of the function for a defined table and field like:
var picklistValues = getPickVals("User","TimeZoneSidKey"); //build array of values

Let me know how it compares,