1

I've to test my sharing code. In my test classs I have to test if user1 creates record then it is visible to all user(400)..for that I have to get all manager id(399 user) based on user1 id...

example user1----->user2(manager of user1)---->user(manager of user2)------>user3(manager of user3)........---->user400(manager of user 399)

Code Is:

public class Parrent{
     public static List<Id> getAll(List<Id> ids){
        List<Id> mIds = new List<Id>();
        for(user u : [select ManagerId from user where id in:ids and ManagerId!=null])
            mIds.add(u.ManagerId); 
       if(mIds.size()>0)
            mIds.addAll(getAll(mIds));
       return mIds;
      }
}

If this code gets all manager id based on the user id

Thanks in advance
Karthick

  • How many users do you have total that could potentially be managers? – Jeremy Nottingham Mar 8 '15 at 1:07
  • What's the limit? I don't see a query inside a for loop - are you getting too many records returned? – Caspar Harmer Apr 7 '15 at 21:00
1

In most companies the number of "levels" of management won't exceed 5 or 10. (Think about how many levels of management you need to go from you to the boss of your company.) So why is your test trying to set up (presumably) more than 100 levels and so causing the SOQL governor limit to be hit?

Perhaps your test should have say 100 users each reporting to 10 managers who each report to 1 manager?

(It is possible to use less queries as the answer to your other question here explains but that is probably not necessary here Getting All Manager Id.)

-1

You just need to bulkify your query, and avoid to use query inside a loop. See this :

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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