The new USING SCOPE clause for SOQL queries lets you limit results by filterScope.
SELECT column_name FROM table_name USING SCOPE filterScope_value
filterScope_value can take one of the following enumeration values:
Everything – All records, for example All Opportunities.
Mine – Records owned by the user running the list view, for example My Opportunities.
Queue – Records assigned to a queue.
Delegated – Records delegated to another user for action: for example, a delegated task. This option is available in API version 17.0 and later.
MyTerritory – Records in the territory of the user seeing the list view. This option is available if territory management is enabled for your organization. This option is available in API version 17.0 and later.
MyTeamTerritory – Records in the territory of the team of the user seeing the list view. This option is available if territory management is enabled for your organization. This option is available in API version 17.0 and later.
Team – Records assigned to a team. This option is available in API version 17.0 and later.
Public with sharing class Sample{
Public List<string> CusrrentUserRole{get;set;}
Public List<String> RolesInHierarchy{get;set;}
Public Sample(){
CusrrentUserRole = New List<string>();
CusrrentUserRole.add([SELECT UserRoleId FROM User Where Id =:UserInfo.getUserId() LIMIT 1].UserRoleId);
}
Public Void getRollInHierarchy(){
RolesInHierarchy = New List<Id>();
RolesInHierarchy = getAllRoleInHierarchy(CusrrentUserRole);
}
Public List<string> getAllRoleInHierarchy (List<Id> UserRole) {
List<string> currentRoleIds = new List<string>();
for(UserRole userRoleName :[SELECT Id,name FROM UserRole Where ParentRoleId = :UserRole AND ParentRoleID != null]){
currentRoleIds.add(userRoleName.id);
}
if(currentRoleIds.size() > 0) {
currentRoleIds.addAll(getAllRoleInHierarchy(currentRoleIds));
}
List<String> RoleList = New List<String>();
for(UserRole r:[SELECT Name From UserRole Where Id In:currentRoleIds]){
RoleList.add(r.name);
}
return RoleList;
}
}
Visualforce Page:
<apex:page controller="Sample">
<apex:form>
<apex:pageBlock>
<apex:commandButton value="Show Roles below my Hierarchy" action="{!getRollInHierarchy}"/>
</apex:pageBlock>
<apex:pageBlock >
<b> Role below in Hierarchy are : </b>{!RolesInHierarchy}
</apex:pageBlock>
</apex:form>
</apex:page>
Output:
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish.AcceptReject