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
kathybbkathybb 

Punctuating a query string with a multi-word picklist choice

I'm sure there is a simple answer to my question, but so far I haven't found it.  I have a Status__c  field that is a picklist.  Some of the entries have more than one word e.g. Sent to Purchaser.  I'm needing a query string declared early on and reused a couple of times.  Her's my latest attempt:

 

public string m_requestQuerybyStatus= [SELECT id, OwnerId, CreatedBy.id, name, new_Item_Description__c, Status__c,Request_Date__c,Receive_by_Date__c,Quantity__c,Item_Requested__r.name,Department__c, Item_Requested__r.Price_per_Unit__c, Extended_Price__c,Purchase_Order__r.id FROM SFDC_Purchase_Requisition__c WHERE (isBlank(Purchase_Order__c)= True) AND (ISPICKVAL(Status__c) = Sent to Purchaser) Limit 50];

The red clause is what is giving me trouble.  I've tried surrounding the sent to purchaser with all kinds of punctuation around it to no avail.  Either it gives an unkinown token: 'Sent' error, or it compiles fine and throws an SOQL query error when I try to run it.

 

Can anyone tell me what I'm doing wrong, or suggest things to try?

 

Thank you in advance for your time and help.

 

Kathybb

k_bentsenk_bentsen

When you say multi-word picklist, do you mean multi-select picklist? If it's just a regular picklist, then your condition should be ISPICKVAL(Status__c, "Sent to Purchaser") = TRUE 

 

If it's a multi-select picklist, then you'll want INCLUDES(Status__c, "Sent to Purchaser") = TRUE

 

On a side note, I didn't even know you could use that kind of syntax in Apex... interesting. Personally, I would change your condition to Status__c = 'Sent to Purchaser', and also Purchase_Order__c = NULL just to keep query cosmetically consistent, but that's just me and my OCD :)