You need to sign in to do that
Don't have an account?
Siddharth Lakhotia
Need Help in writting Test Class when Permission set is assigned via Role??
Hi,
I have written a trigger, where-in I am assigning Permission set to a user based on his roles.
if a user role name contains Sales Manager or Director, Permission set gets assigned to him at the time of Update and Insert.
When the userrole contains Executive , Permission Set gets Deleted automatically at the time of Update and Insert.
Can anyone help me in writting Test Class for the same.
I have written a trigger, where-in I am assigning Permission set to a user based on his roles.
if a user role name contains Sales Manager or Director, Permission set gets assigned to him at the time of Update and Insert.
When the userrole contains Executive , Permission Set gets Deleted automatically at the time of Update and Insert.
Can anyone help me in writting Test Class for the same.
All Answers
You could create a test user with required role ('Sales Manager' or 'Director') and check if the permission Set gets assigned to the inserted user.
Hope it helps.
Thanks.
Gopi
I copied your Test class code . It still gives me 0% coverage
@isTest public class PermSetAssignTest
{
static TestMethod void RoleTest(){
UserRole role = new UserRole(DeveloperName = 'Sales Manager', Name = 'Sales Manager');
insert role;
User u = new User(
ProfileId = [SELECT Id FROM Profile WHERE Name = 'YOUR PROFILE'].Id,
LastName = 'last',
Email = 'testtt@tessst.com',
Username = 'testtt@tessst.com' + System.currentTimeMillis(),
CompanyName = 'TEST',
Title = 'title',
Alias = 'alias',
TimeZoneSidKey = 'America/Los_Angeles',
EmailEncodingKey = 'UTF-8',
LanguageLocaleKey = 'en_US',
LocaleSidKey = 'en_US',
UserRoleId = role.Id
);
Insert u;
PermissionSet perSet = [SELECT Id FROM PermissionSet WHERE Name='China_Allow_Report_Access'];
PermissionSetAssignment permAssnment = [SELECT Id, AssigneeId FROM PermissionSetAssignment WHERE AssigneeId= :u.Id LIMIT 1];
System.assertEquals(perSet.Id,permAssnment.PermissionSetId);
System.runAs(u)
{
PermSetAssignTest pr = new PermSetAssignTest ();
}
}
}
Could you please post your trigger code here.?
Thanks.
Gopi.
Please try the below code:
Hope this will help.
Thanks
Bhargavi.
Thanks once again