You need to sign in to do that
Don't have an account?
Ab
executing test class as specific user
Hello,
I want to execute a test function in test class.
Before executing fucntion i want to create a user with a licence "partner community", how is it posible to achieve ?
thanks for suggestion !
I want to execute a test function in test class.
Before executing fucntion i want to create a user with a licence "partner community", how is it posible to achieve ?
thanks for suggestion !
Id p = [select id from profile where name='Partner Community'].id;
Account ac = new Account(name ='Pradip') ;
insert ac;
Contact con = new Contact(LastName ='Shukla',AccountId = ac.Id);
insert con;
User U = new User(alias = 'test123', email='test123@noemail.com',
emailencodingkey='UTF-8', lastname='Testing', languagelocalekey='en_US',
localesidkey='en_US', profileid = p, country='United States',IsActive =true,
ContactId = con.Id,
timezonesidkey='America/Los_Angeles', username='tester@noemail.com');
lstUser.add(U);
insert lstUser;
system.runAs(U)
All Answers
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_tools_runas.htm
Id p = [select id from profile where name='Partner Community'].id;
User U = new User(alias = 'test123', email='test123@noemail.com',
emailencodingkey='UTF-8', lastname='Testing', languagelocalekey='en_US',
localesidkey='en_US', profileid = p, country='United States',IsActive =true,
timezonesidkey='America/Los_Angeles', username='tester@noemail.com');
lstUser.add(U);
insert lstUser;
system.runAs(U)
{
I used above code it gives meerror..as the user should be associated with a account and contact
Id p = [select id from profile where name='Partner Community'].id;
Account ac = new Account(name ='Pradip') ;
insert ac;
Contact con = new Contact(LastName ='Shukla',AccountId = ac.Id);
insert con;
User U = new User(alias = 'test123', email='test123@noemail.com',
emailencodingkey='UTF-8', lastname='Testing', languagelocalekey='en_US',
localesidkey='en_US', profileid = p, country='United States',IsActive =true,
ContactId = con.Id,
timezonesidkey='America/Los_Angeles', username='tester@noemail.com');
lstUser.add(U);
insert lstUser;
system.runAs(U)