You need to sign in to do that
Don't have an account?
Saravanan @Creation
System.runAs() method on APEX Class.-Urgent
Hi Team,
I have one doubt on the System.runAs() method .
Can I use this system.runAs() in the Apex class not the test class?
I want to use this method in apex class to execute block of code based on the system adminstrator user.
Please help me .If i can use then what are the procedure i need to take care.If not please give me the reson.
Thanks in advance
Hi,
Note: You can only use runAs in test method.
If you want to execute a code for System Admin user then you can do something like below:
Hope this helps :)
Hi ,
Thanks for your quick reply,
So you are telling that we can't use system.runAs method in apex class.Am I right?
I am modifying my above comment as, You can use System.runAs() in apex class but only when it comes under test method.
Please follow below example:
http://developer.force.com/cookbook/recipe/using-system-runas-in-test-methods
If you want execute some code in the context of System Admin you can try the apex logic as I have explained above.
Ok thats fine,
So i will not use this method in apex class.
I have one class with sharing keyword in that i want to query the permissionset assigment.
Logged in user don't have modify all permission. so it will through insufficient privilages. As per the below article .
http://help.salesforce.com/apex/HTViewSolution?id=000163404&language=en_US
please help me how can i resolve this .
because of this i try to use RunAs in the class to query the permission set assigment.
So from what I'm understanding, you want to bypass sharing for that individual query right? You can try something like this:
The inner class will be the only thing that runs outside of sharing context, everything else will still be in sharing context.
Thanks sean ,
Its not working still i am getting the same problem.
Hey Find out this post to know more about System.runAs() Method
http://himanshurana.in/system-runas/
Did you find a solution for this ?