Throwing System.QueryException on Batch Class for field “IsArchived” on Product2












7














We're using Schema.getGlobalDescribe().get(objectName).getDescribe().fields.getMap()to fetch all the fields in Product2 and build a dynamic query. When the string is used in database.query() method, it throws the error below.




No such column 'IsArchived' on entity 'Product2'. If you are
attempting to use a custom field, be sure to append the '__c' after
the custom field name. Please reference your WSDL or the describe call
for the appropriate names.




The query works when I remove "IsArchived" field.
Tried running the code in Execute Anonymous and I'm not getting the same issue. Query retrieves records even when 'IsArchived' is added.










share|improve this question



























    7














    We're using Schema.getGlobalDescribe().get(objectName).getDescribe().fields.getMap()to fetch all the fields in Product2 and build a dynamic query. When the string is used in database.query() method, it throws the error below.




    No such column 'IsArchived' on entity 'Product2'. If you are
    attempting to use a custom field, be sure to append the '__c' after
    the custom field name. Please reference your WSDL or the describe call
    for the appropriate names.




    The query works when I remove "IsArchived" field.
    Tried running the code in Execute Anonymous and I'm not getting the same issue. Query retrieves records even when 'IsArchived' is added.










    share|improve this question

























      7












      7








      7







      We're using Schema.getGlobalDescribe().get(objectName).getDescribe().fields.getMap()to fetch all the fields in Product2 and build a dynamic query. When the string is used in database.query() method, it throws the error below.




      No such column 'IsArchived' on entity 'Product2'. If you are
      attempting to use a custom field, be sure to append the '__c' after
      the custom field name. Please reference your WSDL or the describe call
      for the appropriate names.




      The query works when I remove "IsArchived" field.
      Tried running the code in Execute Anonymous and I'm not getting the same issue. Query retrieves records even when 'IsArchived' is added.










      share|improve this question













      We're using Schema.getGlobalDescribe().get(objectName).getDescribe().fields.getMap()to fetch all the fields in Product2 and build a dynamic query. When the string is used in database.query() method, it throws the error below.




      No such column 'IsArchived' on entity 'Product2'. If you are
      attempting to use a custom field, be sure to append the '__c' after
      the custom field name. Please reference your WSDL or the describe call
      for the appropriate names.




      The query works when I remove "IsArchived" field.
      Tried running the code in Execute Anonymous and I'm not getting the same issue. Query retrieves records even when 'IsArchived' is added.







      soql query product






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Dec 10 '18 at 16:55









      jema

      715




      715






















          2 Answers
          2






          active

          oldest

          votes


















          5














          You should check if the field is accessible before adding it to your query.



          for (SObjectField field : SObjectType.Product2.fields.getMap().values())
          {
          if (field.getDescribe().isAccessible())
          {
          // now you can include it in your query
          }
          }





          share|improve this answer





















          • Thanks! Will try this. I'm using the same user to run the Batch Class and the Query in Dev Console. Not sure why I'm not getting the issue in the latter.
            – jema
            Dec 10 '18 at 17:17






          • 1




            It runs in a different user context.
            – Adrian Larson
            Dec 10 '18 at 17:18






          • 1




            This is (most likely) an API version issue, not a field permissions issue.
            – sfdcfox
            Dec 10 '18 at 18:42



















          4














          It sounds like you've got a mix of API versions in your classes and/or triggers, and this is causing a problem. If you use a utility class to generate your dynamic queries, please make sure the API version is no higher than all other classes that use this utility class. This can cause new fields/objects to be exposed to older versions and cause runtime exceptions such as this one. In this case, it appears your utility class is either API version 43.0 or 44.0, and the class that's trying to use the dynamic query is lower than version 43.0. For an example of a prior version of this error, see this Known Issue. Also read this answer I wrote about why you should keep your API versions all the same.





          As for a solution, consider reducing your utility class(es) down to version 27.0 or so (this is the first time I'm aware of where API versions break describe calls), or bump up the classes that use this/these utility classes to at least version 43.0.






          share|improve this answer





















          • This fixed the issue! Thanks a lot!
            – jema
            Dec 11 '18 at 9:18











          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%2f242000%2fthrowing-system-queryexception-on-batch-class-for-field-isarchived-on-product2%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














          You should check if the field is accessible before adding it to your query.



          for (SObjectField field : SObjectType.Product2.fields.getMap().values())
          {
          if (field.getDescribe().isAccessible())
          {
          // now you can include it in your query
          }
          }





          share|improve this answer





















          • Thanks! Will try this. I'm using the same user to run the Batch Class and the Query in Dev Console. Not sure why I'm not getting the issue in the latter.
            – jema
            Dec 10 '18 at 17:17






          • 1




            It runs in a different user context.
            – Adrian Larson
            Dec 10 '18 at 17:18






          • 1




            This is (most likely) an API version issue, not a field permissions issue.
            – sfdcfox
            Dec 10 '18 at 18:42
















          5














          You should check if the field is accessible before adding it to your query.



          for (SObjectField field : SObjectType.Product2.fields.getMap().values())
          {
          if (field.getDescribe().isAccessible())
          {
          // now you can include it in your query
          }
          }





          share|improve this answer





















          • Thanks! Will try this. I'm using the same user to run the Batch Class and the Query in Dev Console. Not sure why I'm not getting the issue in the latter.
            – jema
            Dec 10 '18 at 17:17






          • 1




            It runs in a different user context.
            – Adrian Larson
            Dec 10 '18 at 17:18






          • 1




            This is (most likely) an API version issue, not a field permissions issue.
            – sfdcfox
            Dec 10 '18 at 18:42














          5












          5








          5






          You should check if the field is accessible before adding it to your query.



          for (SObjectField field : SObjectType.Product2.fields.getMap().values())
          {
          if (field.getDescribe().isAccessible())
          {
          // now you can include it in your query
          }
          }





          share|improve this answer












          You should check if the field is accessible before adding it to your query.



          for (SObjectField field : SObjectType.Product2.fields.getMap().values())
          {
          if (field.getDescribe().isAccessible())
          {
          // now you can include it in your query
          }
          }






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Dec 10 '18 at 17:05









          Adrian Larson

          105k19112235




          105k19112235












          • Thanks! Will try this. I'm using the same user to run the Batch Class and the Query in Dev Console. Not sure why I'm not getting the issue in the latter.
            – jema
            Dec 10 '18 at 17:17






          • 1




            It runs in a different user context.
            – Adrian Larson
            Dec 10 '18 at 17:18






          • 1




            This is (most likely) an API version issue, not a field permissions issue.
            – sfdcfox
            Dec 10 '18 at 18:42


















          • Thanks! Will try this. I'm using the same user to run the Batch Class and the Query in Dev Console. Not sure why I'm not getting the issue in the latter.
            – jema
            Dec 10 '18 at 17:17






          • 1




            It runs in a different user context.
            – Adrian Larson
            Dec 10 '18 at 17:18






          • 1




            This is (most likely) an API version issue, not a field permissions issue.
            – sfdcfox
            Dec 10 '18 at 18:42
















          Thanks! Will try this. I'm using the same user to run the Batch Class and the Query in Dev Console. Not sure why I'm not getting the issue in the latter.
          – jema
          Dec 10 '18 at 17:17




          Thanks! Will try this. I'm using the same user to run the Batch Class and the Query in Dev Console. Not sure why I'm not getting the issue in the latter.
          – jema
          Dec 10 '18 at 17:17




          1




          1




          It runs in a different user context.
          – Adrian Larson
          Dec 10 '18 at 17:18




          It runs in a different user context.
          – Adrian Larson
          Dec 10 '18 at 17:18




          1




          1




          This is (most likely) an API version issue, not a field permissions issue.
          – sfdcfox
          Dec 10 '18 at 18:42




          This is (most likely) an API version issue, not a field permissions issue.
          – sfdcfox
          Dec 10 '18 at 18:42













          4














          It sounds like you've got a mix of API versions in your classes and/or triggers, and this is causing a problem. If you use a utility class to generate your dynamic queries, please make sure the API version is no higher than all other classes that use this utility class. This can cause new fields/objects to be exposed to older versions and cause runtime exceptions such as this one. In this case, it appears your utility class is either API version 43.0 or 44.0, and the class that's trying to use the dynamic query is lower than version 43.0. For an example of a prior version of this error, see this Known Issue. Also read this answer I wrote about why you should keep your API versions all the same.





          As for a solution, consider reducing your utility class(es) down to version 27.0 or so (this is the first time I'm aware of where API versions break describe calls), or bump up the classes that use this/these utility classes to at least version 43.0.






          share|improve this answer





















          • This fixed the issue! Thanks a lot!
            – jema
            Dec 11 '18 at 9:18
















          4














          It sounds like you've got a mix of API versions in your classes and/or triggers, and this is causing a problem. If you use a utility class to generate your dynamic queries, please make sure the API version is no higher than all other classes that use this utility class. This can cause new fields/objects to be exposed to older versions and cause runtime exceptions such as this one. In this case, it appears your utility class is either API version 43.0 or 44.0, and the class that's trying to use the dynamic query is lower than version 43.0. For an example of a prior version of this error, see this Known Issue. Also read this answer I wrote about why you should keep your API versions all the same.





          As for a solution, consider reducing your utility class(es) down to version 27.0 or so (this is the first time I'm aware of where API versions break describe calls), or bump up the classes that use this/these utility classes to at least version 43.0.






          share|improve this answer





















          • This fixed the issue! Thanks a lot!
            – jema
            Dec 11 '18 at 9:18














          4












          4








          4






          It sounds like you've got a mix of API versions in your classes and/or triggers, and this is causing a problem. If you use a utility class to generate your dynamic queries, please make sure the API version is no higher than all other classes that use this utility class. This can cause new fields/objects to be exposed to older versions and cause runtime exceptions such as this one. In this case, it appears your utility class is either API version 43.0 or 44.0, and the class that's trying to use the dynamic query is lower than version 43.0. For an example of a prior version of this error, see this Known Issue. Also read this answer I wrote about why you should keep your API versions all the same.





          As for a solution, consider reducing your utility class(es) down to version 27.0 or so (this is the first time I'm aware of where API versions break describe calls), or bump up the classes that use this/these utility classes to at least version 43.0.






          share|improve this answer












          It sounds like you've got a mix of API versions in your classes and/or triggers, and this is causing a problem. If you use a utility class to generate your dynamic queries, please make sure the API version is no higher than all other classes that use this utility class. This can cause new fields/objects to be exposed to older versions and cause runtime exceptions such as this one. In this case, it appears your utility class is either API version 43.0 or 44.0, and the class that's trying to use the dynamic query is lower than version 43.0. For an example of a prior version of this error, see this Known Issue. Also read this answer I wrote about why you should keep your API versions all the same.





          As for a solution, consider reducing your utility class(es) down to version 27.0 or so (this is the first time I'm aware of where API versions break describe calls), or bump up the classes that use this/these utility classes to at least version 43.0.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Dec 10 '18 at 18:40









          sfdcfox

          248k11190425




          248k11190425












          • This fixed the issue! Thanks a lot!
            – jema
            Dec 11 '18 at 9:18


















          • This fixed the issue! Thanks a lot!
            – jema
            Dec 11 '18 at 9:18
















          This fixed the issue! Thanks a lot!
          – jema
          Dec 11 '18 at 9:18




          This fixed the issue! Thanks a lot!
          – jema
          Dec 11 '18 at 9:18


















          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.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • 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%2f242000%2fthrowing-system-queryexception-on-batch-class-for-field-isarchived-on-product2%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

          Список кардиналов, возведённых папой римским Каликстом III

          Deduzione

          Mysql.sock missing - “Can't connect to local MySQL server through socket”