Throwing System.QueryException on Batch Class for field “IsArchived” on Product2
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
add a comment |
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
add a comment |
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
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
soql query product
asked Dec 10 '18 at 16:55
jemajema
715
715
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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
}
}
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
add a comment |
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.
This fixed the issue! Thanks a lot!
– jema
Dec 11 '18 at 9:18
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%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
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
}
}
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
add a comment |
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
}
}
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
add a comment |
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
}
}
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
}
}
answered Dec 10 '18 at 17:05
Adrian Larson♦Adrian Larson
107k19114243
107k19114243
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
add a comment |
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
add a comment |
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.
This fixed the issue! Thanks a lot!
– jema
Dec 11 '18 at 9:18
add a comment |
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.
This fixed the issue! Thanks a lot!
– jema
Dec 11 '18 at 9:18
add a comment |
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.
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.
answered Dec 10 '18 at 18:40
sfdcfoxsfdcfox
252k11194433
252k11194433
This fixed the issue! Thanks a lot!
– jema
Dec 11 '18 at 9:18
add a comment |
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
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%2f242000%2fthrowing-system-queryexception-on-batch-class-for-field-isarchived-on-product2%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