• lancew
  • NEWBIE
  • 0 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies

Hi,

 

I have a Visualforce page and a controller class.

Using "With Sharing" keyword, i am able to retrieve the records from the Custom object just as a Standard Salesforce functionality does.

Now my requirement is to retrieve all the Subordinate Roles for logged in User that should be displayed in drop-down.

There are more than 400 Roles in my org.

My Role stands 5th or 6th from the top.

 

Even if i use SOQL For loop to get all the Subordinate Roles, i am running in to Too many SOQL queries : 101.

Below is my code.

 

public method1()

         //get Subordinate Roles for the CurrentRole

        for(UserRole[] roleList : [Select id, name, parentroleid from UserRole ur Where ur.ParentRoleId :UserInfo.getUserRoleId() order by name])

        {
            for(UserRole role: roleList)
            {
                currentUserSubDetails.add(role);//Add to list
            }

         }

        

        //Retrieve Subordinate roles for each Role

        for(Integer i=0; i<currentUserSubDetails.size(); i++)
        {
            getRolesAtDeeperLevel(currentUserSubDetails[i]);
        }


 }

 

   private void getRolesAtDeeperLevel(UserRole ur)
    {
        for(UserRole[] roleList : [select id, name, ParentRoleId from UserRole where ParentRoleId = :ur.id order by name])
            for(UserRole role: roleList)
            {
                currentUserSubDetails.add(role);
            }
    }

Can anyone suggest me a solution?

 

Regards OnDem

Message Edited by OnDem Dev on 07-09-2009 10:28 AM