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












3















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


















  • 1





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

    – sfdcfox
    33 mins ago
















3















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


















  • 1





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

    – sfdcfox
    33 mins ago














3












3








3


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 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














  • 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










2 Answers
2






active

oldest

votes


















4














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.




























    2














    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









      4














      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.

























        4














        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.























          4












          4








          4







          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 42 mins ago









          Mike LockettMike Lockett

          763




          763




          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.

























              2














              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




























                2














                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


























                  2












                  2








                  2







                  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 39 mins ago









                  Adrian LarsonAdrian Larson

                  106k19113240




                  106k19113240






























                      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

                      Statuo de Libereco

                      Tanganjiko

                      Liste der Baudenkmäler in Enneberg