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
Muni12345Muni12345 

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
Best Answer chosen by Muni12345
sfdcMonkey.comsfdcMonkey.com
hi vasu
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

NagendraNagendra (Salesforce Developers) 
Hi Vasu,

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: Mark this post as solved if the information helps.

Regards,
Nagendra.P

 
sfdcMonkey.comsfdcMonkey.com
hi vasu
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
 
This was selected as the best answer
Muni12345Muni12345
Hi Piyush,

Thank you, now i got it.

Regards,
Vasu
Piyush Sinha 7Piyush Sinha 7
Awesome!! 
Shubh DShubh D
Thank you!! It helped me a lot!
Manki LalaManki Lala
ModHunters (https://modhunters.com/" target="_self) is one of The Best platforms of Mod Android APK Collection, We share the most popular and latest Modded Android Apps and Games for Free
Tue texoTue texo
ModLooters (https://modlooters.com) is one of the best sites of Mod Android Apk Collection which offers the most popular and latest Android Applications and  Modded Games For Free Download.
Emma Rose 4Emma Rose 4
Download latest soul night mod apk (https://allwish.me/soul-knight-mod-apk-with-unlimited-resources-for-android/) from allwish now.