I am writing a simple before trigger to update a lookup field on lead to user object with the id of owner of record (owner could be a user or a queue). But on update of record i am getting an error.
My code:
trigger FetchTccValues on Lead (before insert, before update) {
Group queue = [Select Id, name from Group where type='Queue' and Name='TCC Counsellors'];
List<GroupMember> queueMembers = [Select Group.Name, UserOrGroupId From GroupMember where GroupId =: queue.Id ];
for( Lead le : Trigger.new ) {
for (GroupMember qm :queueMembers ) {
if( le.ownerid == queue.Id || le.ownerid == qm.UserOrGroupId ) {
le.TCC_Lead_Status__c = le.Status;
le.TCC_Lead_Owner__c = le.ownerid;
}
}
}
}
On updating a record I am getting error:
Apex trigger FetchTccValues caused an unexpected exception, contact your administrator: FetchTccValues: data changed by trigger for field TCC Lead Owner: id value of incorrect type: 00Gp0000000kCaCEAU