Questions tagged [runas]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1 vote
0 answers
59 views

No query results in System.runAs after inserting records by the same user

The issue I am having is that after creating records within the System.runAs block, the user creating these records cannot see them. @TestSetup static void setupData() { User regularUser = new ...
user123647's user avatar
8 votes
3 answers
625 views

Can we prove security using Apex Tests & System.runAs()?

Let's pretend I am working on a Managed Package app that is soon going to Security Review. I have used all the latest and greatest native features (I know some of them are not GA yet) like as user and ...
Robert Sösemann's user avatar
2 votes
1 answer
54 views

Simulate “with sharing” for specified user (in integration)

The need: An external system is querying SF data via an Apex REST API. It authenticates to SF via an integration user account (an M2M integration). We need the data returned by the API to be ...
Brent Bowers's user avatar
  • 3,004
0 votes
2 answers
63 views

Delete records as user NOT in test

Is there a way to programatically delete records as a certain user? RunAs() is only for tests, but for normal Apex classes? There may be an answer here Alternatives to run as, but logging in as the ...
Andrea Voggenreiter's user avatar
6 votes
2 answers
883 views

Using System.runAs in all tests - Best practice or Antipattern?

When doing functional tests I see many people also check the permissions by using System.runAs(userWithRightPermission) in most of their tests. I see good reasons for doing this, because then you ...
Robert Sösemann's user avatar
1 vote
2 answers
834 views

System.runAs not working if system user not selected

I created a very simple method on a before insert trigger, that adds the number 11 to a value if a regular user creates a record, But it doesn't add anything if the service user creates it. So for ...
Json's user avatar
  • 1,557
0 votes
1 answer
1k views

Test class data created before 'runAs' user not visible

My test class sets up a Community User and some data prior to doing a runAs the new user. In the runAs section I call a controller which requires the use of the data I created earlier, but it doesn't ...
Irene's user avatar
  • 1,509
0 votes
1 answer
263 views

List has no rows while executed by system.runas()

I have a apex method which retrieves url parameters and perform SOQL and then DML operation. Here's the apex method, public void updateObjRecord(){ try{ String objId = System....
L Mudiyanse's user avatar
1 vote
1 answer
2k views

system.runas and user's time zone

I am writing a test class for testing an API, which populates the value of an iVAR with the logged in user's time zone. In real time, this API works fine. If the logged in User's time zone is EST, I ...
Sahitya Tarumani's user avatar
0 votes
1 answer
267 views

INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY when System.runAs(u) in a test class

I need to create a Patient_Registration__c (which is a Person Account) under a specific user in my test class. Following is my code in the test class: Profile p = [SELECT Id, Name FROM Profile WHERE ...
Bahman.A's user avatar
  • 768
1 vote
1 answer
248 views

Apex Unit Test giving different results for SOQL query when using runAs

I'm writing a unit test to test code that is being used both by regular salesforce users and the site guest user. In order to do so, I'm using the System.runAs method. I was getting weird results, and ...
hgolov's user avatar
  • 671
4 votes
2 answers
9k views

Can You Change the Running User in Apex Logic?

Can you change the running user in your APEX logic, not just test coverage? The documentation only details out doing System.runAs() for testing purposes. https://developer.salesforce.com/docs/atlas....
Olivia's user avatar
  • 3,369
0 votes
1 answer
2k views

Need to get a list of all scheduled reports/dashboards that belong to my organization, each with its running user

As we have a massive number of scheduled reports in our organization this information will be very useful in maintaining the report schedule. Some users are inactive and some reports are failing due ...
Ranga Wickramadara's user avatar
0 votes
1 answer
245 views

system.runAs gives different result after querying

My class is using with sharing keyword and method has a query on object which system admin only has access. List<Login__c> recList = [select id, clientId__c, clientsecret__c from login__c]; So ...
sf_user's user avatar
  • 2,188
5 votes
1 answer
1k views

Subscribe users to reports run as themselves using API or Apex

I am searching for a way to automate a time-consuming task for an administrator on my team: subscribing numerous users to reports ("Schedule Future Runs", Salesforce Classic). The need to for each ...
David Reed's user avatar
  • 91.1k
10 votes
1 answer
176 views

What is a name of System.runAs construction

As I know Apex is a combination of Java and C# languages (maybe this list should contain more languages). Speaking about System.runAs, documentation says that it is a method. It looks like it is a ...
Oleksandr Berehovskyi's user avatar
0 votes
1 answer
3k views

TestClass User Creation and system.runAs()

I have a requirement for a Trigger on Opportunity while creating a new Opportunity as, Add the Opportunity Owners Manager to Opportunity Team Member with role "Sales Manager" And if Opportunity Owner ...
Robert Thomas's user avatar
0 votes
0 answers
685 views

How do I write a test class for master-detail relationship that has trigger-based validation of group membership?

In my org, I have a pair of objects with a master-detail relationship set up and some trigger-based validation as follows:- Both objects contain a picklist field, Business_Segment__c Both objects ...
Rob Cowell's user avatar
2 votes
0 answers
510 views

Executing a block of code in apex class with context/visibility of a specific user

I need to execute a block of code in apex class with context/visibility of a specific user. This user is mentioned in a custom field of a custom object. The need is similar to System.Runas() method ...
Curious Bee's user avatar
1 vote
1 answer
213 views

Mixed DML Operations in Test Methods - system.RunAs(user) - but why?

Reading the documentation here, the advice is to run certain DML operations within a System.runAs(user) block. I don't really understand why that needs to happen. I know that it works - as my unit ...
Andy Hitchings's user avatar
3 votes
1 answer
820 views

System.runas throwing insert failed error in test class

The error is: System.DmlException: Insert failed. First exception on row 0; first error: DUPLICATE_USERNAME, Duplicate Username.The username already exists in this or another Salesforce ...
Samir's user avatar
  • 2,619
0 votes
1 answer
1k views

SOQL query returns no results when using System.runAs() method [closed]

In my Apex test class, I created a contact and inserted it. When running a SOQL query as an external user, the query returns an empty list. I thought it is because the external user doesn't have ...
yassine's user avatar
  • 43
-1 votes
1 answer
28 views

Page to Run Classes [closed]

I have a urgent requirement to make a page in which list of all classes be there with the check box embedded and having button Run. If i select one or more than one classes and click on run button(Run ...
user25917's user avatar
-3 votes
1 answer
103 views

Page to run Test Classes [duplicate]

I have a urgent requirement to make a page in which list of all classes be there with the check box embedded and having button Run. If i select one or more than one classes and click on run button(Run ...
user25917's user avatar
3 votes
1 answer
792 views

losing runas user context

I'm currently trying to write tests regarding knowledge articles where the user initiating/running the tests does not have a knowledge license. Of course to do this, I need to use runAs User testUser ...
user2610036's user avatar
  • 1,039