function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Kasia Wojewodzka 7Kasia Wojewodzka 7 

test Class assert - permission Set assignment

Dear Community
I am new to writting test classes and I am hoping for your assistance.  
Here is the test class for Assigning Pemssion set to the user based on the User Role. 
It passes  the test but i was advised to update the class to include te assert to prove that the code (in case the flow) performed the actions i expected it to. I am struggling.  
Would you advise how the assert should look like for permision set  assigemnt to the user?  Any help is much appriciated. thank you Kasia 
       

@isTest 
private class Test_Flow_PermissionSetAnimana {
    static testMethod void checkPermissionSetAssigment () {
        List<PermissionSetAssignment> permissionSetList = new List<PermissionSetAssignment>();
        Id permissionSetId = [SELECT Id FROM PermissionSet WHERE Name = 'CAG_EMEA_Animana_Sales_Livestock_Doctors_Access'].Id;
        for (User u : [SELECT ID,UserRole.Name,Profile.Name,IsActive FROM User WHERE  UserRole.Name LIKE 'CAG EMEA Animana CS Rep' AND Profile.Name = 'Field Sales Rep- CAG EMEA' AND IsActive = TRUE]){
            PermissionSetAssignment psa = new PermissionSetAssignment (PermissionSetId = permissionSetId, AssigneeId = u.Id);
            permissionSetList.add(psa);
        }
        try{
            upsert permissionSetList;
        }catch(exception e){
            system.debug('exception caught' + e);
        }
    }
}
AbhishekAbhishek (Salesforce Developers) 
Hi Kasia,

Try the test class as mentioned in the below blog,

https://salesforce.stackexchange.com/questions/47328/how-can-i-assign-a-permission-set-to-a-user-in-a-test-context

It might help you but you have to make some changes based on your scenario.

Thanks.
Kasia Wojewodzka 7Kasia Wojewodzka 7
Thank You Ahishek, I will look at the blog mentioned in your response.