Id p = [select id from profile where name=' XXXX'].id;
Account ac = new Account(name ='Test') ;
insert ac;
Contact con = new Contact(LastName ='testCon',AccountId = ac.Id);
insert con;
User user = new User(alias = 'test123', email='
[email protected]',
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='
[email protected]');
insert user;
system.runAs(user) {
// statements to be executed by this test user.
}
How to execute testing: Profiles
Manual or inside Apex using runAs