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











up vote
7
down vote

favorite












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


























    up vote
    7
    down vote

    favorite












    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
























      up vote
      7
      down vote

      favorite









      up vote
      7
      down vote

      favorite











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









      jema

      714




      714






















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          5
          down vote













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






          • 1




            It runs in a different user context.
            – Adrian Larson
            13 hours ago






          • 1




            This is (most likely) an API version issue, not a field permissions issue.
            – sfdcfox
            12 hours ago


















          up vote
          3
          down vote













          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





















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








            up vote
            5
            down vote













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






            • 1




              It runs in a different user context.
              – Adrian Larson
              13 hours ago






            • 1




              This is (most likely) an API version issue, not a field permissions issue.
              – sfdcfox
              12 hours ago















            up vote
            5
            down vote













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






            • 1




              It runs in a different user context.
              – Adrian Larson
              13 hours ago






            • 1




              This is (most likely) an API version issue, not a field permissions issue.
              – sfdcfox
              12 hours ago













            up vote
            5
            down vote










            up vote
            5
            down vote









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









            Adrian Larson

            104k19111234




            104k19111234












            • 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
              13 hours ago






            • 1




              It runs in a different user context.
              – Adrian Larson
              13 hours ago






            • 1




              This is (most likely) an API version issue, not a field permissions issue.
              – sfdcfox
              12 hours ago


















            • 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
              13 hours ago






            • 1




              It runs in a different user context.
              – Adrian Larson
              13 hours ago






            • 1




              This is (most likely) an API version issue, not a field permissions issue.
              – sfdcfox
              12 hours ago
















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




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




            1




            1




            It runs in a different user context.
            – Adrian Larson
            13 hours ago




            It runs in a different user context.
            – Adrian Larson
            13 hours ago




            1




            1




            This is (most likely) an API version issue, not a field permissions issue.
            – sfdcfox
            12 hours ago




            This is (most likely) an API version issue, not a field permissions issue.
            – sfdcfox
            12 hours ago












            up vote
            3
            down vote













            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

























              up vote
              3
              down vote













              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























                up vote
                3
                down vote










                up vote
                3
                down vote









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









                sfdcfox

                243k10185414




                243k10185414






























                    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

                    Quarter-circle Tiles

                    build a pushdown automaton that recognizes the reverse language of a given pushdown automaton?

                    Mont Emei