You need to sign in to do that
Don't have an account?
ira42
How to query Picklist values?
Since I can't use "DISTINCT" in a SOQL query, I'm trying instead to return the unique values of a picklist, using the PHP toolkit.
In the Products2 table, I am trying to query the distinct values from the Products2.Family picklist. I am using a query along the lines of:
Rather than returning the unique values from the picklist, it's returning multiple family names (I guess for each product in the Products2 table?? Not sure). So instead of:
I am getting:
I am stumped... I really just want to return the families as headers and then display the products (assets) under each family header.
Any ideas?
In the Products2 table, I am trying to query the distinct values from the Products2.Family picklist. I am using a query along the lines of:
Code:
$fam_query = "Select Family FROM Product2";
$fam_response = $mySforceConnection->query(($fam_query));
...
foreach ($fam_response->records as $fam_record) {
echo "<h3>".$fam_record->Family."</h3><br>";
}
Rather than returning the unique values from the picklist, it's returning multiple family names (I guess for each product in the Products2 table?? Not sure). So instead of:
Code:
Product Family One Product Family Two Product Family Three Product Family Four ...
I am getting:
Code:
Product Family One Product Family One Product Family One Product Family Two Product Family Two Product Family Two Product Family Two Product Family Two Product Family Three ...
I am stumped... I really just want to return the families as headers and then display the products (assets) under each family header.
Any ideas?
private function GetOppTypes():void
{
apex.describeSObjects(["Opportunity"],
new AsyncResponder(GetOppTypes_CB, genericFault));
}
private function GetOppTypes_CB(result:Object):void
{
arrOppTypes = result[0].fields['Type'].picklistValues as ArrayCollection;
}
Hope this helps!
-Dean
All Answers
I am very new to SF, and had a look through the API docs, and am a little confused about the syntax for PHP (no PHP examples anywhere in there...). Also, the docs say that 'describeSObject' is now superceded by 'describeSObjects', and again, there aren't any PHP examples, just Java and C#.
Could anyone please provide an example of how to return just the values for the Products2.Family picklist in PHP (I'd rather not return the entire Product2 sObject first)? I'd really appreciate it.
- Ira
private function GetOppTypes():void
{
apex.describeSObjects(["Opportunity"],
new AsyncResponder(GetOppTypes_CB, genericFault));
}
private function GetOppTypes_CB(result:Object):void
{
arrOppTypes = result[0].fields['Type'].picklistValues as ArrayCollection;
}
Hope this helps!
-Dean
If anyone has a update to this article, regarding a query in PHP for specifying a picklist value in the WHERE clause, please post it!
I did find a post in he forums on this topic. It should be more widely disseminated.
You can query a picklist just like a string, if you only want one value. for two values "... WHERE Field_Name__c includes ('val1','val2') LIMIT 10" or for multi-select: "... WHERE Field_Name__c = 'val1;val2' LIMIT 10"
one side reference:
http://boards.developerforce.com/t5/Apex-Code-Development/Selecting-a-picklist-value-programmatically/m-p/214229
for the other users of Force.com Flex (flexforforce), this seems the simplest way in Flex:
BaseApplication.metadataCache.getField("type", "field");
Simple, but AFAIK undocumented.