+ Start a Discussion
Salesforce BlitzSalesforce Blitz 

Convert from ID to user object

I have following code:

List<user> TLSPuserlist=[Select id,Name,Email from User where UserRole.Name in:userRoles AND IsActive = true];
List<user> lst_TeamLead = new List<user>();       
 for(user u : TLSPuserlist)
{
  set<id> subord= new set<id>();            
  subord=RoleUtilsModified2.getRoleSubordinateUsers(u.Id);
  If(subord.size()>0 && subord!=NULL)
  {
       for(Id id1 : subord)
        {
             If(id1.Last_Edited_Object__c !=NULL && id1.Last_Edited_Object_Date__c > d || id1.Last_Activity_Type__c !=NULL &&    Last_Activity_Date__c > d) 
               {
                        unediteduseridlist.add(id1);
                }
       }
}


I am getting the following error:
Error: Compile Error: Variable does not exist: Last_Activity_Date__c at line 488 column 132

I have the field Last_Activity_Date__c  on User Object...
The subord for loop(  for(Id id1 : subord)  ) contains ids of all users...I need User usL subord kinda thing, so that i can do the logic and go ahead...How to achieve this..


Thanks in adv
Laxman Lax
Best Answer chosen by Salesforce Blitz
Alexander TsitsuraAlexander Tsitsura
Hi,

You can query all needed users to map using subord set if ids.
Map<Id, User> usersMap = new Map<Id, User>([
  SELECT Id, Name, Last_Edited_Object__c, Last_Edited_Object_Date__c, Last_Activity_Type__c, Last_Activity_Date__c
    FROM User
   WHERE ID IN :subord
]);

and the retrieve User from map in your for loop
User u = usersMap.get(id1);

and then use u.Last_Activity_Date__c insead of id1.Last_Activity_Date__c 

Thanks,
Alex