You did not query the `Managerid` in your first SOQL, hence the error. Replace the following User u = [select id, Email, Name from user LIMIT 10]; With this User u = [select id, Email, Manager__c Name from user LIMIT 10];