Able To Run As Another User - Ideas - Salesforce Trailblazer Community
Trailblazer Community

All Ideas

Idea Details

Post an Idea
500  Points
Idea has been posted. Give it an upvote or downvote.

Able To Run As Another User

Not Categorized

There are times that you don't want to give permissions to specific users permanently, so it would be useful if you could temporarily turn on and off running code under a certain user.

Eg: to allow users to create data in Custom Settings requires to either turn on Customize Applications permissions or to give Delegated System Admin privileges to Non System Admin users.

The only problem with Customize Applications and Delegated System Admin privileges is that it opens the door to greater permissions for those users.

The answer will be to temporarily give permissions in code using System.runas() but this is only allowed in testmethods

If it was possible to run code like below in normal code

Profile prID = [Select id From Profile where Name Like 'System Administrator' LIMIT 1];
        list<User> usr = [Select id From User where and IsActive=true limit 1];//take 1 user which will always exist 
        if (usr.size() > 0){
                TCode_ManagementArea__c newtcode = new TCode_ManagementArea__c ();
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.FATAL, 'There has been an issue saving these records. There is no active System Administrator.'));

Merge Idea · Flag

  • Upvotes
  • Downvotes



from AppExchange

Help us to keep IdeaExchange clean by pointing out overlapping ideas. We'll investigate your suggestion and merge the ideas if it makes sense.



Thanks for your merge suggestion. We will review it shortly and merge the ideas if applicable.

Salesforce takes abuse situations very seriously. Examples of abuse include but are not limited to posting of offensive language or fraudulent statements. To help us process your request as quickly as possible, please fill out the form below describing the situation. For privacy and security reasons, the final outcome of an abuse case may not be revealed to the person who reported it.


Thank you for your feedback. We take abuse seriously and will investigate this issue and take appropriate action.