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
ClintProdClintProd 

Getting picklist options

Does anyone have any clear examples for getting the options from a picklist from either a standard Salesforce object or a custom object? I am sure I have to use one of the describe commands to do this, but I cannot find any examples for this. Thanks.
jf317820jf317820
Picklist Field Type

Picklist fields contain a list of one or more items from which a user chooses a single item. They display as drop-down lists in the Salesforce user interface. One of the items can be configured as the default item.

In the Field object associated with theDescribeSObjectResult, the restrictedPicklist field defines whether the field is a restricted picklist or not. The API does not enforce the list of values for advisory (unrestricted) picklist fields on create or update. When inserting an unrestricted picklist field that does not have a PickListEntry, the system creates an “inactive” picklist value. This value can be promoted to an “active” picklist value by adding the picklist value in the Salesforce user interface.

When creating new, inactive picklists, the API checks to see if there is a match. This check is case-insensitive.

In the Field object associated with theDescribeSObjectResult, the PicklistValues field contains an array of items (PickListEntry objects). Each PickListEntry defines the item’s label, value, and whether it is the default item in the picklist (a picklist has no more than one default value).

Enumerated fields support localization of the labels to the language of the user. For example, for the ForecastCategory field on an Opportunity, the value “Omitted” may be translated to various languages. The enumerated field values are fixed and do not change with a user’s language. However, each value may have a specified “label” field that provides the localized label for that value. You must always use the value when inserting or updating a field. The query call always returns the value, not the label. The corresponding label for a value in theDescribeSObjectResult should be used when displaying the value to the user in any user interface.

The API supports the retrieval of the certain picklists in the following objects: CaseStatus, ContractStatus, LeadStatus, OpportunityStage, PartnerRole, SolutionStatus, TaskPriority, and TaskStatus. Each object represents a value in the respective picklist. These picklist entries always specify some other piece of information, such as whether the status is converted, and so on. Your client application can invoke the query call on any of these objects (such as CaseStatus) to retrieve the set of values in the picklist, and then use that information while processing other objects (such as Cases) to determine more information about those objects (such as a given case). These objects are read-only via the API. To modify items in picklists, you must use the Salesforce user interface.

Greg HGreg H
Here is a practical example where I pull the Time Zone values off the user record and display in a div tag with the id equal to "output".
 
Code:
try {
 var docHTML = "<div>"; //html holder
 var oTable = sforce.connection.describeSObject("User"); //connect to user table
 var oFields = oTable.fields; //get all fields from that table
 for (var a=0; a<oFields.length; a++) { //loop through all the fields
  if (oFields[a].name=="TimeZoneSidKey") { //if the field is the time zone field
   var oPicklistVals = oFields[a].picklistValues; //look at all the picklist values for field
   var displayName = oFields[a].name; //used to id the field in the display of results
   var count = oPicklistVals.length; //get count of values
   for (var b=0; b<oPicklistVals.length; b++) { //loop through all picklist values
    docHTML += oPicklistVals[b].value+"<br>"; //displat one row per value
   }
  }
 }
 docHTML += "</div><div class=\"pShowMore\">"+count+" picklist values for "+displayName+"</div>";
 document.getElementById("output").innerHTML = docHTML;
} catch(e) {
 alert(e);
}
 
Using this code you should be able to look at any table (custom or standard) and pull back the picklist values for a specific field on the table.
 
I hope you find this useful but let me know if you have any other questions,
-greg
 
ClintProdClintProd
Thanks for the example, it was a big help and very well documented. Only thing I needed to change was the "int a" in your the start of your for loops. Had to use the var keyword instead.
ClintProdClintProd
My mistake, you had it right. It was me who put the int keyword in there.
 
ArunYadwadArunYadwad
Hi,
 
I have the following requirements.
#1.
There is a Picklist field in my custom object.This field contains some of the user names.
When I submit the form, an Email Notification has to go to the user whose name is selected in the Picklist.
 
We may have to pull the Email IDs from SFDC Databse by using picklist values and use them in Work Flow Rules. But how do we do that.? or is there any other way of doing it?
 
#2.
We need a very similar button like 'Mail Merge' in our form for Ex:'Send Quote to CSR'.
When the user clicks on this button, it will pick a mail merge template from system, pulls in all the values from custom object and sends it to the user whose name is selected in Picklist.
 
I am new to S-Control and Apex programming, but I am good at Javascript programming.
 
Can any one help me?
 
Thank you,
-Arun