Questions tagged [runas]
The runas tag has no usage guidance.
26
questions
2
votes
1
answer
91
views
runAs() not working as expected
When I run the following piece of code:
@isTest
private static void testKybc() {
String methodName = 'testKybc';
ObjectUtil.debugLogBegin('TMPTriggerHandler_Test', methodName, '');
Map&...
1
vote
0
answers
68
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 ...
8
votes
3
answers
973
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 ...
2
votes
1
answer
62
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 ...
0
votes
2
answers
91
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 ...
6
votes
2
answers
1k
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 ...
1
vote
2
answers
1k
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 ...
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 ...
0
votes
1
answer
278
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....
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 ...
0
votes
1
answer
316
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 ...
1
vote
1
answer
271
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 ...
4
votes
2
answers
10k
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....
0
votes
2
answers
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 ...
0
votes
1
answer
253
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 ...
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 ...
10
votes
1
answer
178
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 ...
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 ...
0
votes
0
answers
716
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 ...
2
votes
0
answers
560
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 ...
1
vote
1
answer
217
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 ...
3
votes
1
answer
849
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 ...
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 ...
-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 ...
-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 ...
3
votes
1
answer
839
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 ...