Is there any way to set set salesforce userid from apex test class
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
2
down vote
favorite
Is there any way to set set salesforce userid from apex test class.
For Example:
SetupTest st = new SetupTest();
Account billing = st.Account('Billing');
billing.Name = 'Test_BillingAccount';
billing.Atlas_Id__c = 'a_' + billing.Name;
insert billing;
PageReference pageRef = Page.CreateSalesOrder;
pageRef.getParameters().put('id',string.valueOf(billing.Id));
Test.setCurrentPage(pageRef);
In the above code am passing dynamic account id from test page, Is there a way to pass userid(userinfo.getuserid()) like this?
apex unit-test
add a comment |Â
up vote
2
down vote
favorite
Is there any way to set set salesforce userid from apex test class.
For Example:
SetupTest st = new SetupTest();
Account billing = st.Account('Billing');
billing.Name = 'Test_BillingAccount';
billing.Atlas_Id__c = 'a_' + billing.Name;
insert billing;
PageReference pageRef = Page.CreateSalesOrder;
pageRef.getParameters().put('id',string.valueOf(billing.Id));
Test.setCurrentPage(pageRef);
In the above code am passing dynamic account id from test page, Is there a way to pass userid(userinfo.getuserid()) like this?
apex unit-test
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
Is there any way to set set salesforce userid from apex test class.
For Example:
SetupTest st = new SetupTest();
Account billing = st.Account('Billing');
billing.Name = 'Test_BillingAccount';
billing.Atlas_Id__c = 'a_' + billing.Name;
insert billing;
PageReference pageRef = Page.CreateSalesOrder;
pageRef.getParameters().put('id',string.valueOf(billing.Id));
Test.setCurrentPage(pageRef);
In the above code am passing dynamic account id from test page, Is there a way to pass userid(userinfo.getuserid()) like this?
apex unit-test
Is there any way to set set salesforce userid from apex test class.
For Example:
SetupTest st = new SetupTest();
Account billing = st.Account('Billing');
billing.Name = 'Test_BillingAccount';
billing.Atlas_Id__c = 'a_' + billing.Name;
insert billing;
PageReference pageRef = Page.CreateSalesOrder;
pageRef.getParameters().put('id',string.valueOf(billing.Id));
Test.setCurrentPage(pageRef);
In the above code am passing dynamic account id from test page, Is there a way to pass userid(userinfo.getuserid()) like this?
apex unit-test
apex unit-test
edited 2 hours ago
Adrian Larsonâ¦
101k19107226
101k19107226
asked 2 hours ago
user3214361
173
173
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
4
down vote
You are looking for the system.runAs
method.
User someOtherUser = new User(/*required fields*/);
system.runAs(someOtherUser)
system.assertEquals(
someOtherUser.Id,
UserInfo.getUserId(),
'The running user should be changed'
);
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
You are looking for the system.runAs
method.
User someOtherUser = new User(/*required fields*/);
system.runAs(someOtherUser)
system.assertEquals(
someOtherUser.Id,
UserInfo.getUserId(),
'The running user should be changed'
);
add a comment |Â
up vote
4
down vote
You are looking for the system.runAs
method.
User someOtherUser = new User(/*required fields*/);
system.runAs(someOtherUser)
system.assertEquals(
someOtherUser.Id,
UserInfo.getUserId(),
'The running user should be changed'
);
add a comment |Â
up vote
4
down vote
up vote
4
down vote
You are looking for the system.runAs
method.
User someOtherUser = new User(/*required fields*/);
system.runAs(someOtherUser)
system.assertEquals(
someOtherUser.Id,
UserInfo.getUserId(),
'The running user should be changed'
);
You are looking for the system.runAs
method.
User someOtherUser = new User(/*required fields*/);
system.runAs(someOtherUser)
system.assertEquals(
someOtherUser.Id,
UserInfo.getUserId(),
'The running user should be changed'
);
answered 2 hours ago
Adrian Larsonâ¦
101k19107226
101k19107226
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f233664%2fis-there-any-way-to-set-set-salesforce-userid-from-apex-test-class%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password