You need to sign in to do that
Don't have an account?
Salesforce Blitz
Create Test class for creating users with roles
HI guys,
I have a class which fetches all users below a particular role in a role hierarchy and sends mail to those whio have not edited in last 1 week.
I need to write a test class to it.
I need to Create few users.In which one should be Teal head of set of users.
How do i need to create roles in role hierarchy and
how to create multiple users in test class with Roles
Kindly reply asap. urgnt Req
Thanka s lot in adv,
Laxman jagz
I have a class which fetches all users below a particular role in a role hierarchy and sends mail to those whio have not edited in last 1 week.
I need to write a test class to it.
I need to Create few users.In which one should be Teal head of set of users.
How do i need to create roles in role hierarchy and
how to create multiple users in test class with Roles
Kindly reply asap. urgnt Req
Thanka s lot in adv,
Laxman jagz
For create role use code below For create user
For create many users you need add all to list and then insert all in one transaction for avoid dml limit.
As a common practice, if your question is answered, please choose 1 best answer.
But you can give every answer a thumb up if that answer is helpful to you.
Thanks,
Alex
Please have a look on the similar post,
https://developer.salesforce.com/forums/ForumsMain?id=906F0000000BYaZIAW
You can also try this code:-
@isTest static void UserCreate() {
UserRole obj=new UserRole(Name= 'ABC');
insert obj;
Profile pf= [Select Id from profile where Name='System Administrator'];
String orgId=UserInfo.getOrganizationId();
String dateString=String.valueof(Datetime.now()).replace(' ','').replace(':','').replace('-','')
Integer RandomId=Integer.valueOf(Math.rint(Math.random()*1000000));
String uniqueName=orgId+dateString+RandomId;
User uu=new User(firstname = 'ABC',
lastName = 'XYZ',
email = uniqueName + '@test' + orgId + '.org',
Username = uniqueName + '@test' + orgId + '.org',
EmailEncodingKey = 'ISO-8859-1',
Alias = uniqueName.substring(18, 23),
TimeZoneSidKey = 'America/Los_Angeles',
LocaleSidKey = 'en_US',
LanguageLocaleKey = 'en_US',
ProfileId = pf.Id,
UserRoleId = obj.Id);
}
As a common practice, if your question is answered, please choose 1 best answer.
But you can give every answer a thumb up if that answer is helpful to you.