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
Ravi Kumar 6740Ravi Kumar 6740 

How to use many conditions in Where using : in SOQL?

AbhinavAbhinav (Salesforce Developers) 
Hi Ravi,

Its not clear.Could you please elaborate.

Thanks!
 
PriyaPriya (Salesforce Developers) 

Hi Ravi,

You can add multiple field expressions to a condition expression by using logical operators.
For e.g., - SELECT Id FROM Contact WHERE Name LIKE 'A%' AND MailingState='California'

To know more about it, kindly refer the documentation :- 
https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_conditionexpression.htm#:~:text=You%20can%20add%20multiple%20field,%25'%20AND%20MailingState%3D'California'

 

Please mark it as Best Answer so that it can help others in the future.

Regards,

Priya Ranjan

 

Suraj Tripathi 47Suraj Tripathi 47
Hi,
You should use conditions according to your requirement.

=:  it is used in the soql query to compare with the variable.
other we can simply use = if we are just comparing single name.
 

string s='test1';
string s1='test2';
List<Contact> contactList= [SELECT name FROM Contact WHERE LastName =:s or FirstName =: s1];
system.debug('con- '+contactList);

List<Contact> contactList2= [SELECT name FROM Contact WHERE LastName ='Test' or FirstName ='Test'];
system.debug('con- '+contactList2);

get more details from here:-
https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_conditionexpression.htm#:~:text=You%20can%20add%20multiple%20field,%25'%20AND%20MailingState%3D'California'

Please mark it as Best Answer if it helps you.

Thanks & Regards
Suraj Tripathi

 
Ravi Kumar 6740Ravi Kumar 6740
I want to  add filters in lightning datatable, so i used lightning select to show drop down list and i am able to fetch picklist value and send it to server side controller but was not able to query the list of recodrs holds good for both the condition.
Server Side Controller Method :
@AuraEnabled
    public static List<Account> getAccount(String res,String rvalue){
        return [Select Id,Name ,AnnualRevenue,Description,NumberOfEmployees,Industry,Rating,Phone from Account Where Industry =:r AND Rating=:rvalue ] ; 
          }
PriyaPriya (Salesforce Developers) 
I guess you are querying based on the wrong variable name. it should be 
Where Industry =:res 

And other reason could be that there will be no records in your Org as per the mentioned condition. 
You may check your data by querry it in SOQL editor in dev console.
Suraj Tripathi 47Suraj Tripathi 47

Hi Ravi,

There is no such varaible as "r" in you code and you are using in your query "Industry =:r"

Correct code:

@AuraEnabled
    public static List<Account> getAccount(String res,String rvalue){
      system.debug('res::'+res);
      system.debug('rvalue::'+rvalue);
        return [Select Id,Name ,AnnualRevenue,Description,NumberOfEmployees,Industry,Rating,Phone from Account Where Industry =:res AND Rating=:rvalue ] ; 
          }


Also, check you are receiving data in res and rvalue. for better understanding use system.debug();

Please mark it as the Best Answer if your query is solved.

Thank you!