I have a code like this -
//there i get all the Jaipur city employee list
List<Employee> employeeList = [select ID from Employee where city='Jaipur'];
Now i need to get Departments of these Employees. I do like -
List<ID> idsList = new List<ID>();
//Iterate employeeList to get employee IDS
for(Employee emp : employeeList){
idsList.add(emp.id);
}
// Then get Department List of these ids
List<Department> departmentList = [select ID, name from Department where empId IN: idsList];
I need to ask Is there any other way to get Departments? i mean i don't want to iterate over employeeList to form idsList and then use those ids in next query to get departmentList.
can't i get IDS list directly from employeeList without iterating it completely?