You need to sign in to do that
Don't have an account?

Difference between "IN", "=" operator, "=:" operator and ":" in SOQL query
what is the exact difference between "IN", "=" operator, "=:" operator and ":" in SOQL query, Where we can use exactly?
Please clear my confussion.
Thanks in advance
Please clear my confussion.
Thanks in advance
use ":" bind variable for access varible in query like
String MyName = 'vasu';
List<Contact> ListOfName = [SELECT FirstName, LastName FROM Contact WHERE FirstName = : MyName];
use "=" operator is simple Equal operator in query like-:
List<Contact> ListOfName = [SELECT FirstName, LastName FROM Contact WHERE FirstName = 'vasu'];
[give contact list where firstName = (equal) vasu]
use IN operator in soql for refer LIST or SET direct in query like
List<String> lstOfStr = new List<String>{'testName','testName2'};
List<Contact> ListOfName = [SELECT FirstName, LastName FROM Contact WHERE FirstName IN : lstOfStr];
[here also use bind ":" operator for access varible value in query ]
i hope it helps you
Let me inform if it helps you
Thanks
All Answers
If you're looking for the value of a single variable, then it would make sense that the operator would be "equal" to the value of the specified variable, it wouldn't be "IN" the variable as if your query has to sort among a group of records.
According to syntax, if your variable is a list or set, you'd expect the value to be "IN" the list or set, not "equal" to the value of the list or set. Often times it makes no difference which one you use for a list or set as Apex is smart enough to understand what you intended. It could also be a question of did you want all the values contained in the list or set, or only some of them that make the difference on which to use that clarifies the intent, but generally, if a list or set, using "IN" would be the proper syntax.
Where it's essential to use "IN" is when you use a map. A value of an operator can't be "equal" to a map, can it? Instead, it has to be contained "IN" the map.
For more information please check this link:
- https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_comparisonoperators.htm
Mark this post as solved if the information helps.Regards,
Nagendra.P
use ":" bind variable for access varible in query like
String MyName = 'vasu';
List<Contact> ListOfName = [SELECT FirstName, LastName FROM Contact WHERE FirstName = : MyName];
use "=" operator is simple Equal operator in query like-:
List<Contact> ListOfName = [SELECT FirstName, LastName FROM Contact WHERE FirstName = 'vasu'];
[give contact list where firstName = (equal) vasu]
use IN operator in soql for refer LIST or SET direct in query like
List<String> lstOfStr = new List<String>{'testName','testName2'};
List<Contact> ListOfName = [SELECT FirstName, LastName FROM Contact WHERE FirstName IN : lstOfStr];
[here also use bind ":" operator for access varible value in query ]
i hope it helps you
Let me inform if it helps you
Thanks
Thank you, now i got it.
Regards,
Vasu