SOQL Query Where Id “In” Versus “Equals”(=)
I just stumbled upon a soql query where somebody did the following
List<String> names = new List<String>{'John', 'Moe', 'Jeanette', 'Tony'};
List<Client__c> clients = [
SELECT Id
FROM Client__c
WHERE First_Name__c = :names
];
I am not familiar with the usage of the equal sign(=) to check against a list/set as opposed to WHERE First_Name__c IN :names
.
I am having a hard time finding the difference as it seems like using =
works similarly but does it work the same way? Are there any dangers to using it?
apex soql where clause
add a comment |
I just stumbled upon a soql query where somebody did the following
List<String> names = new List<String>{'John', 'Moe', 'Jeanette', 'Tony'};
List<Client__c> clients = [
SELECT Id
FROM Client__c
WHERE First_Name__c = :names
];
I am not familiar with the usage of the equal sign(=) to check against a list/set as opposed to WHERE First_Name__c IN :names
.
I am having a hard time finding the difference as it seems like using =
works similarly but does it work the same way? Are there any dangers to using it?
apex soql where clause
1
Note: this special behavior is not available in any API; it only works in Apex code.
– sfdcfox
33 mins ago
add a comment |
I just stumbled upon a soql query where somebody did the following
List<String> names = new List<String>{'John', 'Moe', 'Jeanette', 'Tony'};
List<Client__c> clients = [
SELECT Id
FROM Client__c
WHERE First_Name__c = :names
];
I am not familiar with the usage of the equal sign(=) to check against a list/set as opposed to WHERE First_Name__c IN :names
.
I am having a hard time finding the difference as it seems like using =
works similarly but does it work the same way? Are there any dangers to using it?
apex soql where clause
I just stumbled upon a soql query where somebody did the following
List<String> names = new List<String>{'John', 'Moe', 'Jeanette', 'Tony'};
List<Client__c> clients = [
SELECT Id
FROM Client__c
WHERE First_Name__c = :names
];
I am not familiar with the usage of the equal sign(=) to check against a list/set as opposed to WHERE First_Name__c IN :names
.
I am having a hard time finding the difference as it seems like using =
works similarly but does it work the same way? Are there any dangers to using it?
apex soql where clause
apex soql where clause
asked 54 mins ago
ArthleteArthlete
845515
845515
1
Note: this special behavior is not available in any API; it only works in Apex code.
– sfdcfox
33 mins ago
add a comment |
1
Note: this special behavior is not available in any API; it only works in Apex code.
– sfdcfox
33 mins ago
1
1
Note: this special behavior is not available in any API; it only works in Apex code.
– sfdcfox
33 mins ago
Note: this special behavior is not available in any API; it only works in Apex code.
– sfdcfox
33 mins ago
add a comment |
2 Answers
2
active
oldest
votes
I've not seen a difference functionally; I strongly prefer using IN as that is what would be required in SQL, and it it more accurate, and more descriptive.
First_Name__c is not logically equal to a list.
Using the syntax First_Name___c IN :names
makes it clear that names is a collection, and that the developer knows that it's a collection
New contributor
add a comment |
They are functionally equivalent. I agree with Mike that IN
is more syntactically clear, but either one works.
See also: How to find out if an Object is a collection or single value?
This equivalence can be quite useful when building dynamic SOQL.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "459"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f247214%2fsoql-query-where-id-in-versus-equals%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
I've not seen a difference functionally; I strongly prefer using IN as that is what would be required in SQL, and it it more accurate, and more descriptive.
First_Name__c is not logically equal to a list.
Using the syntax First_Name___c IN :names
makes it clear that names is a collection, and that the developer knows that it's a collection
New contributor
add a comment |
I've not seen a difference functionally; I strongly prefer using IN as that is what would be required in SQL, and it it more accurate, and more descriptive.
First_Name__c is not logically equal to a list.
Using the syntax First_Name___c IN :names
makes it clear that names is a collection, and that the developer knows that it's a collection
New contributor
add a comment |
I've not seen a difference functionally; I strongly prefer using IN as that is what would be required in SQL, and it it more accurate, and more descriptive.
First_Name__c is not logically equal to a list.
Using the syntax First_Name___c IN :names
makes it clear that names is a collection, and that the developer knows that it's a collection
New contributor
I've not seen a difference functionally; I strongly prefer using IN as that is what would be required in SQL, and it it more accurate, and more descriptive.
First_Name__c is not logically equal to a list.
Using the syntax First_Name___c IN :names
makes it clear that names is a collection, and that the developer knows that it's a collection
New contributor
New contributor
answered 42 mins ago
Mike LockettMike Lockett
763
763
New contributor
New contributor
add a comment |
add a comment |
They are functionally equivalent. I agree with Mike that IN
is more syntactically clear, but either one works.
See also: How to find out if an Object is a collection or single value?
This equivalence can be quite useful when building dynamic SOQL.
add a comment |
They are functionally equivalent. I agree with Mike that IN
is more syntactically clear, but either one works.
See also: How to find out if an Object is a collection or single value?
This equivalence can be quite useful when building dynamic SOQL.
add a comment |
They are functionally equivalent. I agree with Mike that IN
is more syntactically clear, but either one works.
See also: How to find out if an Object is a collection or single value?
This equivalence can be quite useful when building dynamic SOQL.
They are functionally equivalent. I agree with Mike that IN
is more syntactically clear, but either one works.
See also: How to find out if an Object is a collection or single value?
This equivalence can be quite useful when building dynamic SOQL.
answered 39 mins ago
Adrian Larson♦Adrian Larson
106k19113240
106k19113240
add a comment |
add a comment |
Thanks for contributing an answer to Salesforce Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f247214%2fsoql-query-where-id-in-versus-equals%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Note: this special behavior is not available in any API; it only works in Apex code.
– sfdcfox
33 mins ago