function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Vishnu SanthoshVishnu Santhosh 

Test class run failing with : System.QueryException: Insufficient permissions: secure query included inaccessible field

Hi,

While running the test class for code coverage, I am facing an issue to run it succesfully as it is throwing the below exception :

System.QueryException: Insufficient permissions: secure query included inaccessible field

My guess is that Test class is run in system mode which does not require permissions for field. (Please correct me if i am wrong)

I had also went through the test class to check if any profile/user is mentioned in the test class and that is not the case.

One thing to note is that, Test class is running sucesfully in one org with good code coverage, but its not running on another org and says it failed due to the above mentioned exception.

Any work around/ Idea to overcome this issue ?

Thank you :)

Best Answer chosen by Vishnu Santhosh
AbhinavAbhinav (Salesforce Developers) 
Is the query having WITH SECURITY_ENFORCED?

checked below blog you will get understanting about that exception :

https://www.sfdcstop.com/2020/03/validate-crud-permission-before-soqldml.html

If it helps mark it as best answer.

Thanks!

All Answers

AbhinavAbhinav (Salesforce Developers) 
Is the query having WITH SECURITY_ENFORCED?

checked below blog you will get understanting about that exception :

https://www.sfdcstop.com/2020/03/validate-crud-permission-before-soqldml.html

If it helps mark it as best answer.

Thanks!
This was selected as the best answer
Vishnu SanthoshVishnu Santhosh
Hi Abhinav,
This was the reason why the test class was running in User Mode and checking for the access permissions for the current user.
Thought it was running in System Mode.
Thank you for sharing 👍
kapil vanarasikapil vanarasi
what was the solution to fix the test class issue?