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
Lukasz PiziakLukasz Piziak 

Multiple criteria selection on Where SOQL query

Hi,

I'm looking for help with creating WHERE query.
My current query:
 salesOrderList = [SELECT Name, SCMC__Customer_Account__c, Type__c, SCMC__Current_Promise__c, SCMC__Shipment_Status__c 
    From SCMC__Sales_Order__c Where Type__c='Production_Sales_Order' Order by SCMC__Current_Promise__c];
I would like to add another filter condition
Where Type__c='Production_Sales_Order'  
AND 
SCMC__Shipment_Status__c='Pending Pulling All Items' 
AND
SCMC__Shipment_Status__c='Pending Pulling Partial Items Ordered' 

Thank you for any help.
Best Answer chosen by Lukasz Piziak
KaranrajKaranraj
Lukasz - You want to bring get the Sales order records whicah contains shipment status as "Pending pulling All items" and Shipment status is "Pendin pulling partial Items order'" if so then you need to include OR condition in your query. 
salesOrderList = [SELECT Name, SCMC__Customer_Account__c, Type__c, SCMC__Current_Promise__c, SCMC__Shipment_Status__c 
    From SCMC__Sales_Order__c Where Type__c='Production_Sales_Order' and (SCMC__Shipment_Status__c='Pending Pulling All Items' OR SCMC__Shipment_Status__c='Pending Pulling Partial Items Ordered' ) Order by SCMC__Current_Promise__c];
AND operator will check if the both the condition are true
OR operator will check if any one of the condition is true

 

All Answers

Alexander TsitsuraAlexander Tsitsura
Hi Lukasz,

I believe that you want 'Pending Pulling All Items'  OR 'Pending Pulling Partial Items Ordered'  instead of AND
try this soql
salesOrderList = [SELECT Name, SCMC__Customer_Account__c, Type__c, 
                         SCMC__Current_Promise__c, SCMC__Shipment_Status__c 
                   From SCMC__Sales_Order__c 
                   Where Type__c = 'Production_Sales_Order' 
                         AND SCMC__Shipment_Status__c IN ('Pending Pulling All Items', 
                                                          'Pending Pulling Partial Items Ordered')
                   Order by SCMC__Current_Promise__c];

As a common practice, if your question is answered, please choose 1 best answer. 
But you can give every answer a thumb up if that answer is helpful to you.

Thanks,
Alex
KaranrajKaranraj
Lukasz - You want to bring get the Sales order records whicah contains shipment status as "Pending pulling All items" and Shipment status is "Pendin pulling partial Items order'" if so then you need to include OR condition in your query. 
salesOrderList = [SELECT Name, SCMC__Customer_Account__c, Type__c, SCMC__Current_Promise__c, SCMC__Shipment_Status__c 
    From SCMC__Sales_Order__c Where Type__c='Production_Sales_Order' and (SCMC__Shipment_Status__c='Pending Pulling All Items' OR SCMC__Shipment_Status__c='Pending Pulling Partial Items Ordered' ) Order by SCMC__Current_Promise__c];
AND operator will check if the both the condition are true
OR operator will check if any one of the condition is true

 
This was selected as the best answer
Lukasz PiziakLukasz Piziak
Thank you guys, working fine for me now.