You need to sign in to do that
Don't have an account?

Collecting id in Recursion
Hi folks,
Can anyone tell me how to collect all Ids using recursion?
Here's my code:
public class ParrentIdClass2 {
public static List<Id> getParrentId(Id i){
String ParentUserName;
List<Id> ParentUserId=new List<Id>();
User ur = new User(id=i);
ur = [select ur.Id, ur.Name, ur.ManagerId from User ur where ur.Id =: i];
System.debug('UrId='+ur.Id);
ParentUserId.add(ur.Id);
System.debug('UrName='+ur.Name);
System.debug('UrManagerId='+ur.ManagerId);
if(ur.ManagerId != null){
ParentUserId.addAll(getParrentId(ur.ManagerId));
}
return ParentUserId;
}
}
They above code doesnt collect all iids
Please Help!
Can anyone tell me how to collect all Ids using recursion?
Here's my code:
public class ParrentIdClass2 {
public static List<Id> getParrentId(Id i){
String ParentUserName;
List<Id> ParentUserId=new List<Id>();
User ur = new User(id=i);
ur = [select ur.Id, ur.Name, ur.ManagerId from User ur where ur.Id =: i];
System.debug('UrId='+ur.Id);
ParentUserId.add(ur.Id);
System.debug('UrName='+ur.Name);
System.debug('UrManagerId='+ur.ManagerId);
if(ur.ManagerId != null){
ParentUserId.addAll(getParrentId(ur.ManagerId));
}
return ParentUserId;
}
}
They above code doesnt collect all iids
Please Help!
List<Id> ParentUserId=new List<Id>();
public static List<Id> getParrentId(Id i){
String ParentUserName;
ur = [select Id, Name, ManagerId from User where Id =: i];
if(ur.ManagerId != null)
if(ur.ManagerId != null){
ParentUserId.add(ur.ManagerId);
getParrentId(ur.ManagerId);
}
return ParentUserId;
}
}
Hope this helps!