What is the difference between the IN and = operator in SOQL Salesforce?
" : " bind variable for access variable in the query as below
String MyFirstName = 'sampath';
List<Contact> ListOfName = [SELECT FirstName FROM Contact WHERE FirstName = : MyFirstName];
" = " operator is simple Equal operator in the query as below
List<Contact> ListOfName = [SELECT FirstName FROM Contact WHERE FirstName = 'sampath'];
Note :- gets list of contacts where firstName = sampath (equals to sampath)
" IN " operator in soql for refer LIST or SET direct in the query as below
List<String> lstOfStr = new List<String>{'Sai','Sampath'};
List<Contact> ListOfName = [SELECT FirstName FROM Contact WHERE FirstName IN : lstOfStr];
Note :- here also we use bind ":" operator for access variable value in soql query.
Hope above info might be helpful, thank you :-)
No comments:
Post a Comment