You need to sign in to do that
Don't have an account?
PS81
Using hidden fields in APEX query
Hi
I need to have a dynamic query to retrieve the fields in Campaign object (keeping aside the governace limit) but when i execute a sample query with all the fields in query editor I see an error "No such column 'hierarchyactualcost' on entity 'Campaign'."
when i set this field as visible for profile and then execute the query i do not see this error. Any ways on how to fix this so that i can perform the query without any errors?
the code to get the fields from the object is:
Map <String, Schema.SObjectField> objectFields = Campaign.getSobjectType().getDescribe().fields.getMap();
for (SObjectField fld : objectFields.values()) {
query += ' ' + fld + ', ';
}
is there a way to see if the field is set as not visible and if so then do not consider the field in the query?
I need to have a dynamic query to retrieve the fields in Campaign object (keeping aside the governace limit) but when i execute a sample query with all the fields in query editor I see an error "No such column 'hierarchyactualcost' on entity 'Campaign'."
when i set this field as visible for profile and then execute the query i do not see this error. Any ways on how to fix this so that i can perform the query without any errors?
the code to get the fields from the object is:
Map <String, Schema.SObjectField> objectFields = Campaign.getSobjectType().getDescribe().fields.getMap();
for (SObjectField fld : objectFields.values()) {
query += ' ' + fld + ', ';
}
is there a way to see if the field is set as not visible and if so then do not consider the field in the query?
The only exceptions to this rule are Apex code that is executed with the executeAnonymouscall and Chatter in Apex.
You are querying from query editor which is part of excuteAnoymouscall, so apex is applying object and field level permission.
I did same from Setup>Apex Class > New and included folllowing code in the editor and i was able to query the field.
So you will be able to get the value in apex class as it runs in system context but you won't be able to display on VF pages.
Hope this will help. :)
All Answers
then go to "'hierarchyactualcost"
click on that link and then click the button "Set Field-Level Security"
Check if your profile has access to the field.
Regards,
Sanpreet
You can check if field is accessible by login user you can difine your query based on that.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_perms_enforcing.htm
Apex generally runs in system context; that is, the current user's permissions, field-level security, and sharing rules aren’t taken into account during code execution. The only exceptions to this rule are Apex code that is executed with the executeAnonymouscall and Chatter in Apex. executeAnonymous always executes using the full permissions of the current user. For more information on executeAnonymous, see Anonymous Blocks.
The only exceptions to this rule are Apex code that is executed with the executeAnonymouscall and Chatter in Apex.
You are querying from query editor which is part of excuteAnoymouscall, so apex is applying object and field level permission.
I did same from Setup>Apex Class > New and included folllowing code in the editor and i was able to query the field.
So you will be able to get the value in apex class as it runs in system context but you won't be able to display on VF pages.
Hope this will help. :)