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
Ashish MalikarAshish Malikar 

Want to logged-in as another user in apex

Hi All,

I want to logged-in as another user to execute some part of code, like in test classes we can use System.runAs(). But this is not applicable in non-test context. Is there another alternative to do this in non-test apex class?

 
Arpit Jain7Arpit Jain7
Since Apex code runs as System Admin, I am not sure you will need to login as another user. But still if you want this you can use Rest API/SOAP API to achieve the same. Below is one of the example how to do the same with Rest API

https://www.cloudforce4u.com/2015/10/rest-api-integration-salesforce-apex.html

Thanks
Arpit

Please mark this answer as SOLVED and BEST ANSWER if it helps you.