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
Yogesh KulkarniYogesh Kulkarni 

Change RunAs user from javascript call

Hi,

Can I change the current user for execution of some lines of code while using javascript behind detail button? I normally do this using System.RunAs in apex.

Thanks,
Yogesh
Best Answer chosen by Yogesh Kulkarni
Andy BoettcherAndy Boettcher
System.RunAs is used in Unit Tests - not normal Apex execution.  The Apex that you run will run as the user executing it.

All Answers

Andy BoettcherAndy Boettcher
System.RunAs is used in Unit Tests - not normal Apex execution.  The Apex that you run will run as the user executing it.
This was selected as the best answer
Andries.NeyensAndries.Neyens
Hey,

too bad you can't do that. Only intended for Unit tests.
But what are you trying to accomplish ?

Do you have troubles with sharing rules? you can fix that with the Without sharing keyword.
Ownership of records? can also be done with apex code
And if it is something completly different, you can solve that with a batch job running as another user.
 
Yogesh KulkarniYogesh Kulkarni
Hi Andries,

I wanted to run a code as different user as logged in users are not permitted to few changes. I wanted to bypass that by using a user login who has permission. Now I accomplished that using separate VF page and carrying transaction in the controller code and bypassing validation using flags in code.

Thanks for your reply.

Regards,
Yogesh