SOQL Query Where Id “In” Versus “Equals”(=)












4















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?










share|improve this question


















  • 2





    Note: this special behavior is not available in any API; it only works in Apex code.

    – sfdcfox
    13 hours ago











  • @sfdcfox Can you provide an example if you don't mind? What API would this not work in?

    – Arthlete
    12 hours ago






  • 1





    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
    12 hours ago
















4















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?










share|improve this question


















  • 2





    Note: this special behavior is not available in any API; it only works in Apex code.

    – sfdcfox
    13 hours ago











  • @sfdcfox Can you provide an example if you don't mind? What API would this not work in?

    – Arthlete
    12 hours ago






  • 1





    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
    12 hours ago














4












4








4


1






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?










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 13 hours ago









ArthleteArthlete

852515




852515








  • 2





    Note: this special behavior is not available in any API; it only works in Apex code.

    – sfdcfox
    13 hours ago











  • @sfdcfox Can you provide an example if you don't mind? What API would this not work in?

    – Arthlete
    12 hours ago






  • 1





    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
    12 hours ago














  • 2





    Note: this special behavior is not available in any API; it only works in Apex code.

    – sfdcfox
    13 hours ago











  • @sfdcfox Can you provide an example if you don't mind? What API would this not work in?

    – Arthlete
    12 hours ago






  • 1





    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
    12 hours ago








2




2





Note: this special behavior is not available in any API; it only works in Apex code.

– sfdcfox
13 hours ago





Note: this special behavior is not available in any API; it only works in Apex code.

– sfdcfox
13 hours ago













@sfdcfox Can you provide an example if you don't mind? What API would this not work in?

– Arthlete
12 hours ago





@sfdcfox Can you provide an example if you don't mind? What API would this not work in?

– Arthlete
12 hours ago




1




1





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
12 hours ago





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
12 hours ago










2 Answers
2






active

oldest

votes


















5














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






share|improve this answer








New contributor




Mike Lockett is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




























    3














    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.






    share|improve this answer























      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
      });


      }
      });














      draft saved

      draft discarded


















      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









      5














      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






      share|improve this answer








      New contributor




      Mike Lockett is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.

























        5














        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






        share|improve this answer








        New contributor




        Mike Lockett is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.























          5












          5








          5







          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






          share|improve this answer








          New contributor




          Mike Lockett is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.










          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







          share|improve this answer








          New contributor




          Mike Lockett is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          share|improve this answer



          share|improve this answer






          New contributor




          Mike Lockett is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          answered 13 hours ago









          Mike LockettMike Lockett

          1113




          1113




          New contributor




          Mike Lockett is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.





          New contributor





          Mike Lockett is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.






          Mike Lockett is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.

























              3














              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.






              share|improve this answer




























                3














                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.






                share|improve this answer


























                  3












                  3








                  3







                  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.






                  share|improve this answer













                  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.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 13 hours ago









                  Adrian LarsonAdrian Larson

                  106k19113241




                  106k19113241






























                      draft saved

                      draft discarded




















































                      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.




                      draft saved


                      draft discarded














                      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





















































                      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







                      Popular posts from this blog

                      Ponta tanko

                      Tantalo (mitologio)

                      Erzsébet Schaár