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
grrepITgrrepIT 

Picklist

Hi

HOw to query the picklist values from API?
For example , Select Local_Name_for_xx__c from Contact gets all the records from contact rather than picklist field?

Also how can we add more items to this pick list through API?

Thanks in advance.
GrantMGrantM
Hi

You cannot query picklists like other object through the API.
This needs to be done using the DescribeSObject (i found this wierd at first too)

Here is my code of how i do this

//Get a sforce service
sforce.SforceService binding = Security.GetSforceService(); //Thats my class that retrieves it

//Get Your DescribeSObjectResult
sforce.DescribeSObjectResult dsr = sforceservice.describeSObject("Contact"); //Name of object picklist belongs to

//Loop through this, and find your required picklist
for(int i = 0; i < dsr.fields.Length; i++)
{
if(dsr.fields[i].type == sforce.fieldType.picklist && dsr.fields[i].name == "[NameOfYourPickList]")
{
MyPicklist = dsr.fields[i].picklistValues;
}
}

//********************************************
// MyPicklist is an array of 'PicklistEntry'
// Where each PicklistEntry.value will be
// the items in the picklist
//********************************************


Now, in terms of adding more items through the Api
I don't believe you can do this,
Though, through the API, you can update picklist fields with any value you want,
i don't think the Master Picklist options are changed though

Hope This Helps

GrantM