Salesforce 测试类创建User 并以此用户运行

创建user,这些是必填的

Profile saleProfile = [ select id from Profile where Name = '市场部人员'];
List userList = [select id,ProfileId,Alias,TimeZoneSidKey,LocaleSidKey,
LanguageLocaleKey,EmailEncodingKey from User where id =:UserInfo.getUserId()];
 
User u = new User();
u.Username='[email protected]';
u.LastName='supUser';
u.Email='[email protected]';
u.Alias=userList[0].Alias;
u.TimeZoneSidKey=userList[0].TimeZoneSidKey;
u.ProfileId=saleProfile.Id;//简档
u.LocaleSidKey=userList[0].LocaleSidKey;
u.LanguageLocaleKey=userList[0].LanguageLocaleKey;
u.EmailEncodingKey=userList[0].EmailEncodingKey;
u.CommunityNickname='supUser';
insert u;
在测试类中以创建的用户进行测试
//新创建的用户,作为测试对象
system.runAs(saleUser)


你可能感兴趣的:(测试类,Salesforce,测试类,User)