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.
soql query product
add a comment |
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.
soql query product
add a comment |
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.
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 14 hours ago
jema
714
714
add a comment |
add a comment |
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
}
}
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
add a comment |
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.
add a comment |
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
}
}
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
add a comment |
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
}
}
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
add a comment |
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
}
}
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 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
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
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
add a comment |
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.
add a comment |
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.
add a comment |
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.
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 12 hours ago
sfdcfox
243k10185414
243k10185414
add a comment |
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.
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.
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