I have written following apex class:

public with sharing class Persmissionset
public static PermissionPagerWrapper fetchPermission(Decimal pageNumber ,Integer recordToDisply) {
      Integer pageSize = recordToDisply;
      Integer offset = ((Integer)pageNumber - 1) * pageSize;

    // create a instance of wrapper class.
    PermissionPagerWrapper obj =  new PermissionPagerWrapper();
    // set the pageSize,Page(Number), total records and accounts List(using OFFSET)   
        obj.pageSize = pageSize;
        obj.page = (Integer) pageNumber;
        obj.total = [SELECT count() FROM PermissionSetAssignment Where Assignee.isActive = True AND permissionSet.IsOwnedByProfile = FALSE];
        obj.permissonAssignment = [SELECT PermissionSet.Name, PermissionSet.Id, PermissionSet.Label, Assignee.Name, Assignee.Id, Assignee.Profile.Name,Assignee.ProfileId,Assignee.UserRole.Name,Assignee.Profile.UserType,Assignee.Email FROM PermissionSetAssignment 
       Where Assignee.isActive = True AND permissionSet.IsOwnedByProfile = FALSE 
       ORDER BY Assignee.Name LIMIT :recordToDisply OFFSET :offset];
    // return the wrapper class instance .
        return obj;

 // create a wrapper class with @AuraEnabled Properties    
 public class PermissionPagerWrapper {
    @AuraEnabled public Integer pageSize {get;set;}
    @AuraEnabled public Integer page {get;set;}
    @AuraEnabled public Integer total {get;set;}
    @AuraEnabled public List<PermissionSetAssignment> permissonAssignment {get;set;}

But here I am stuck in writing test class for this object.

Can some one help here as of now I am writing this test class but its giving error for me:

public class PermissionsetTest
  static testMethod void PermissionTest()
 List<> saList = Persmissionset.fetchPermission(10 ,100);

  • 1
    It is comlaining about List<> saList, you haven't mention any object for the List, however, your method returns PermissionPagerWrapper, so it is better to write smth like this: PermissionPagerWrapper ans = Persmissionset.fetchPermission(10 ,100); – Mariia Illarionova Jul 19 '19 at 10:00
  • I tried using the above mentioned but getting invalid identifier error. – Pushpesh Bisht Jul 19 '19 at 10:06

PermissionPageWrapper is an inner class. In your test class, you must refer to it as Persmissionset.PermissionPageWrapper. This will allow you to correctly declare

List<Persmissionset.PermissionPageWrapper> saList = Persmissionset.fetchPermission(10 ,100);

and then write assertions.

To avoid being dependent on org configuration, your test class will have to do some work to create a test-context user and assign them a permission set, or you will need to use a mocking pattern to allow you to inject the query results so that you can actually page through results.

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.