You need to sign in to do that
Don't have an account?

issue with trigger that changes closed tasks owner
I have this trigger on accounts wich is based on a custom look up field (users) Gestor_a__c
If Gestor_a__c has any open task related to an account, when I change the acount Gestor the ownership of the open task related to him/her also change to the new Gestor.
It is working fine, but it also changes completed tasks??
what I am mising?
trigger reAssignTask on Account (after update) { Set<Id> accId = new Set<Id>(); MAP<Id , ID> accId_NewMangID = new MAP<Id , ID>(); Set<Id> oldManagerId = new Set<Id>(); for(Account a : trigger.new) { if(a.Gestor_a__c != trigger.oldMap.get(a.id).Gestor_a__c) { accId.add(a.id); oldManagerId.add(trigger.oldMap.get(a.id).Gestor_a__c); accId_NewMangID.put(a.id , a.Gestor_a__c); } } List<Task> listTask = [Select id , OwnerID , whatID From Task where whatID in: accId and OwnerId in: oldManagerId]; for(Task t : listTask) { t.OwnerID = accId_NewMangID.get(t.whatID); } update listTask; }
try this
All Answers
Try adding a condition to you select to only include open tasks.
try this
This time I was not too far away, i did it like you said before u told me but didn´t work because the org instead of completed the value had a similar but different name
Now it works like a charm!!
Thanks for your help my friend!!
Your welcome my friend,
la bienvenida a mi amigo :)