Wednesday, 3 January 2018





What is the difference between the IN and = operator in SOQL Salesforce?




Below is the definition and example for " IN " and " = " operators
 
" : " 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

Tools for Lightning Web Component Development

 Below are the tools required for Web Component Development 1. Chrome Browser (Prefered) You can download it from Google 2. Visual Studio Co...