Skip to main content

public static Set<Id> getAllMyParentRoleID(Set<Id> roleIdsSet, Map<Id, UserRole> orgRoleMap){

        Set<Id> CalledroleIdsSet = new Set<Id>();

        for(String filteredRoleId : roleIdsSet){

            if(orgRoleMap.containsKey(filteredRoleId) 

               && (String)orgRoleMap.get(filteredRoleId).ParentRoleID != '' 

               && orgRoleMap.get(filteredRoleId).ParentRoleID != NULL){

                CalledroleIdsSet.add(orgRoleMap.get(filteredRoleId).ParentRoleID);

            }

        }

        if(CalledroleIdsSet.size() > 0){

            CalledroleIdsSet.addAll(getAllMyParentRoleID(CalledroleIdsSet, orgRoleMap));

        }

        return CalledroleIdsSet;

    }
1 个回答
  1. 2021年3月18日 12:35
    You can use the following code to get started

     

    @isTest

    private class Task14_Test {

    @isTest static void beforeupdateTest() {

    mapUserRole = new Map<Id, UserRole>([Select Id, Name, ParentRoleID from UserRole limit 10000]);

    Set<ID> currentRoleIds = new Set<ID>();

    // get all of the roles underneath the passed roles

    for(UserRole userRole :[select Id from UserRole where ParentRoleId]) {

    currentRoleIds.add(userRole.Id);

    }

    // Perform test

    Test.startTest();

    className.getAllMyParentRoleID(currentRoleIds, mapUserRole)

    Test.stopTest();

    }

    }

    Let me know if this helps, if it does, please mark this answer as best so that others facing the same issue will find this information useful. Thank you
0/9000