Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

The tag has no usage guidance.

0
votes
1answer
34 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
1answer
44 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 ...
0
votes
2answers
308 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
1answer
154 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
1answer
42 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 ...
2
votes
1answer
58 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 ...
7
votes
1answer
118 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
1answer
223 views

How can I find all reports which has a certain “Running User” for a Scheduled Report?

I mistakenly thought that I would be able to go to Monitoring > Scheduled Jobs page and use the 'Submitted by' column to tell me which report schedules would be problematic when we deactivate a user. ...
0
votes
1answer
605 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
0answers
244 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 ...
1
vote
0answers
97 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
1answer
115 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
1answer
470 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
1answer
727 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
1answer
26 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
1answer
76 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
1answer
443 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 ...