Skip to main content
1 of 2
Alex Tennant
  • 13.7k
  • 5
  • 58
  • 85

In a trigger on Lead (which is what you're using), Trigger.new only contains the list of Lead objects that has been inserted/updated/deleted/undeleted (depending on context), which is why you cannot iterate over it as a collection of User objects.

You can however build your own list of user IDs and then use that to get the User objects you require:

Set<ID> userIds = new Set<Id>();

for(Lead aLead : Trigger.new)
{
    userIds.add(aLead.CreatedById);
}

List<Id> userMap = 
[
    SELECT 
        Id
    FROM 
        User 
    WHERE 
        Id IN :userIds 
        AND UserType = 'PowerPartner' 
        AND IsActive = true
];
Alex Tennant
  • 13.7k
  • 5
  • 58
  • 85