You need to sign in to do that
Don't have an account?
scriptagent
I want to set an other TestUser as the Manager of RunAs User....is that possible ?
RunAs function problem - please help
Good morning,
I wrote a testMethod, in which I use a runAs user, like:
Code:
Profile pr2 = [select id from profile where name='Standard User']; User u = new User(Manager=OTHERTESTUSER,alias = 'standt', email='standarduser@testorg.com',emailencodingkey='UTF-8', lastname='Testing', languagelocalekey='en_US',localesidkey='en_US', profileid = pr2.Id,timezonesidkey='America/Los_Angeles', username='standarduser@testorg.com'); System.runAs(u) {...}
I want to set an other TestUser as the Manager of RunAs User....is that possible ?
I have attempted to create and insert a new User before the System.runAs statement, but that works somehow not..hmm.
Thanks a lot in advance for help!
Peter
If so, I was able to insert 2 user records (setting the ManagerId of the 2nd one with the User Id of the 1st one), then I set the runAs().
Here is the code:
Thanks for your replies !
I have tested the code (...insert u_manager; ...) and I get still this error message:
"LICENSE_LIMIT_EXCEEDED"
But I can create an User manual, so I don't understand this message...what's the matter?
Thx, Peter
I would recommend for testing purposes, you make yourself the manager of the new user you create. Then your test should work.
What if the number of actual production licenses have reached the max and I have to deploy codes and the test methods that create a new user for testing, then what's my alternative?
I can change the test codes to retrieve an actual user with the right profile I want, but that will change lots of test codes. It's kind of lame that test codes, which have been clearly annotated @isTest and testMethod for testing, invoke Salesforce license limit.
Don't tell me that I can't deploy without getting a new license in order to pass the test code coverage.
Please help.
I met an interesting problem with RunAs() in my test method for a trigger.
If I use Test.startTest() and Test.stopTest( ) together with RunAs() function, I got the error: System.Exception: Too many System.runAs() invocations:1
When I use RunAt() alone without Test.startTest() and Test.stopTest( ), ther is no error at all.
Can anyone explain why?
Thanks
I just hit the same problem trying to deploy to production: License Limit Exceeded. I had to temporarily deactivate a real user so that I could get my code to deploy since my test method creates a user to fulfull the RunAs function.
Have you hit this too? Vote up this idea so Salesforce gets the message:
http://ideas.salesforce.com/article/show/10097249/Test_Methods_need_to_ignore_License_Limits
if your search found this thread, it looks like this idea was delivered recently.