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
BobPBobP 

Multiple Conditions in a Apex Class soql Query

I have a apex class for a visualforce page with the soql query that i would like to addition conditions but when i try to add the change i get an error. I'm not sure how my query should be disigned.
"
Error: Compile Error: Expecting ']' but was: 'OR' at line 13 column 227"
 
// Used on the account page updated 1-31-2020
Public Class VF_SiteServicePartnerAllController{
   private Account acc;
   public List<Site_Service_Partner__c> sspList {get;set;}
   
   public VF_SiteServicePartnerAllController(ApexPages.StandardController sp){
       acc = (Account)sp.getRecord();
       sspList = new List<Site_Service_Partner__c>();
       sspList = [SELECT Id,Name,Site_Account__c,Primary_Field_Contact__c,Service_Partner__c,
                  Service_Partner_Owner__c,Service_Partner_Owner_Mobile__c,Service_Partner_Owner_Email__c,
                  Primary_Field_Email__c,Primary_Field_Mobile__c,Service_Partner_Site_Status__c, 
                  Contracted_Services__c,Secondary_Field_Contact__c,Secondary_Field_Email__c,Secondary_Field_Mobile__c,
                  Service_Partner_Start_Date__c,Service_Partner_End_Date__c,Service_Partner_Main_Phone__c,Trade__c,Supported_Trade__c  FROM Site_Service_Partner__c WHERE Site_Account__c =: acc.Id AND Trade__c includes('Land') OR Trade__c includes('Snow') AND Service_Partner_Site_Status__c = 'Active' ];

    
    Set<Id> bidId = new  Set<Id>();  
    for(Site_Service_Partner__c bs:sspList){
       bidId.add(bs.Id);
    }
     
   }

}




 
Best Answer chosen by BobP
SarvaniSarvani
Hi Bob,

Please replace your SOQL in the code with below: 

sspList=[SELECT Id,Name,Site_Account__c,Primary_Field_Contact__c,Service_Partner__c, Service_Partner_Owner__c,Service_Partner_Owner_Mobile__c,Service_Partner_Owner_Email__c, Primary_Field_Email__c,Primary_Field_Mobile__c,Service_Partner_Site_Status__c, Contracted_Services__c,Secondary_Field_Contact__c,Secondary_Field_Email__c,Secondary_Field_Mobile__c, Service_Partner_Start_Date__c,Service_Partner_End_Date__c,Service_Partner_Main_Phone__c,Trade__c,Supported_Trade__c FROM Site_Service_Partner__c WHERE Site_Account__c =: acc.Id AND (Trade__c includes('Land' ,'Snow') AND Service_Partner_Site_Status__c = 'Active' )]; 
 
Assuming Trade__c field is multiselect picklist. Incase if your Trade__c is picklist data type replace "Includes" in your query with IN operator.

Hope this helps! Please mark as best if it does.

Thanks

All Answers

SarvaniSarvani
Hi Bob,

Please replace your SOQL in the code with below: 

sspList=[SELECT Id,Name,Site_Account__c,Primary_Field_Contact__c,Service_Partner__c, Service_Partner_Owner__c,Service_Partner_Owner_Mobile__c,Service_Partner_Owner_Email__c, Primary_Field_Email__c,Primary_Field_Mobile__c,Service_Partner_Site_Status__c, Contracted_Services__c,Secondary_Field_Contact__c,Secondary_Field_Email__c,Secondary_Field_Mobile__c, Service_Partner_Start_Date__c,Service_Partner_End_Date__c,Service_Partner_Main_Phone__c,Trade__c,Supported_Trade__c FROM Site_Service_Partner__c WHERE Site_Account__c =: acc.Id AND (Trade__c includes('Land' ,'Snow') AND Service_Partner_Site_Status__c = 'Active' )]; 
 
Assuming Trade__c field is multiselect picklist. Incase if your Trade__c is picklist data type replace "Includes" in your query with IN operator.

Hope this helps! Please mark as best if it does.

Thanks
This was selected as the best answer
BobPBobP
Hi Servani,

Thank you for helping me. I was able to figure this out but I will mark you answer as best.