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
Vidya DVidya D 

Test method to test insufficient privileges

My Org has two different profiles. One Profile can create some  materials required by Org and 2 nd profice consumes that org by associating material with account through junction object - VF page and cotroller extension.  When I use 2nd profile and and access Account through UI, I get expected error message insufficient privileges. 

I want to write test case to test insufficient privileges by creating 2 different users one for each. But I am not able to simulate the test method. Now I am wondering is it possible to write test method to test insufficient privileges?
Best Answer chosen by James Loghry
pconpcon
Inside a test method, you can create a new User with the restricted profile.  Then you can use System.runAs [1] to execute the code as that User.  This should do what you are looking for.

[1] https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_testing_tools_runas.htm