function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
LIM AI KHOONLIM AI KHOON 

Get data from map

Hi, in user map have id and name. This code is to check if userMap contains the name from field HOT__C, so the ID from the map will be the owner ID.

The thing is, this code will take the last id from the map, not take the id according to the checking name. May I know how to fix this?
Map<Id, User> userMap = new Map<Id, User>([SELECT Id, Name FROM User where UserRole.name like'HO%']);
for (User u : userMap.values()) {
    for (Centive__c centive: Trigger.new) {
        if(u.Name.contains(centive.HOT__c)){
            centive.OwnerId = u.id;
        } 
    }
}