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
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
2
Note: this special behavior is not available in any API; it only works in Apex code.
– sfdcfox
Jan 18 at 19:53
@sfdcfox Can you provide an example if you don't mind? What API would this not work in?
– Arthlete
Jan 18 at 20:46
2
Any of them. For example, in the Apex Data Loader, you cannot sayselect name from lead where name = ('john doe','jane doe')
. This is one of the few magic behaviors of SOQL in Apex.
– sfdcfox
Jan 18 at 20:52
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
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
apex soql
edited Jan 26 at 18:27
Adrian Larson♦
108k19115243
108k19115243
asked Jan 18 at 19:32
ArthleteArthlete
919715
919715
2
Note: this special behavior is not available in any API; it only works in Apex code.
– sfdcfox
Jan 18 at 19:53
@sfdcfox Can you provide an example if you don't mind? What API would this not work in?
– Arthlete
Jan 18 at 20:46
2
Any of them. For example, in the Apex Data Loader, you cannot sayselect name from lead where name = ('john doe','jane doe')
. This is one of the few magic behaviors of SOQL in Apex.
– sfdcfox
Jan 18 at 20:52
add a comment |
2
Note: this special behavior is not available in any API; it only works in Apex code.
– sfdcfox
Jan 18 at 19:53
@sfdcfox Can you provide an example if you don't mind? What API would this not work in?
– Arthlete
Jan 18 at 20:46
2
Any of them. For example, in the Apex Data Loader, you cannot sayselect name from lead where name = ('john doe','jane doe')
. This is one of the few magic behaviors of SOQL in Apex.
– sfdcfox
Jan 18 at 20:52
2
2
Note: this special behavior is not available in any API; it only works in Apex code.
– sfdcfox
Jan 18 at 19:53
Note: this special behavior is not available in any API; it only works in Apex code.
– sfdcfox
Jan 18 at 19:53
@sfdcfox Can you provide an example if you don't mind? What API would this not work in?
– Arthlete
Jan 18 at 20:46
@sfdcfox Can you provide an example if you don't mind? What API would this not work in?
– Arthlete
Jan 18 at 20:46
2
2
Any of them. For example, in the Apex Data Loader, you cannot say
select name from lead where name = ('john doe','jane doe')
. This is one of the few magic behaviors of SOQL in Apex.– sfdcfox
Jan 18 at 20:52
Any of them. For example, in the Apex Data Loader, you cannot say
select name from lead where name = ('john doe','jane doe')
. This is one of the few magic behaviors of SOQL in Apex.– sfdcfox
Jan 18 at 20:52
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
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
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
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
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
answered Jan 18 at 19:44
Mike LockettMike Lockett
1363
1363
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 Jan 18 at 19:47
Adrian Larson♦Adrian Larson
108k19115243
108k19115243
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
2
Note: this special behavior is not available in any API; it only works in Apex code.
– sfdcfox
Jan 18 at 19:53
@sfdcfox Can you provide an example if you don't mind? What API would this not work in?
– Arthlete
Jan 18 at 20:46
2
Any of them. For example, in the Apex Data Loader, you cannot say
select name from lead where name = ('john doe','jane doe')
. This is one of the few magic behaviors of SOQL in Apex.– sfdcfox
Jan 18 at 20:52