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

URGENT:not updating contact fields in task
I have created a custom field in Task(Activity) and i want to update that field with Phone field from contacts.
Main reason for writting a trigger is i want to show it in a Task list view(visualforce page).
Here is the Trigger:
trigger CopyPhone on Task (after update) { Set<Id> contactIds = new Set<Id>(); for(Task t : trigger.new){ String wId = t.WhoId; if(wId!=null && wId.startsWith('003') && !contactIds.contains(t.WhoId)){ contactIds.add(t.WhoId); } } List<Contact> taskcons = [Select Id,Phone from Contact where Id in :contactIds]; Map<Id, Contact> conMap = new Map<Id, Contact>(); for(Contact c : taskcons){ conMap.put(c.Id,c); } for(Task t : trigger.new){ String wId = t.WhoId; if(wId!=null && wId.startswith('003')){ Contact thisCon = conMap.get(t.WhoId); if(thisCon!=null){ t.ThirdPartyNo__c = thisCon.Phone; } } } }
Thanks in Advance.........
Needs to be "before update" / "before insert". As a side note, you can make this more efficient:
Some notes here:
The query optimizer will silently ignore ID values that are not contact IDs (at least, it has in the past, I don't see why that would have changed).
You can put a query result directly into a map without looping through the list.
All Answers
Needs to be "before update" / "before insert". As a side note, you can make this more efficient:
Some notes here:
The query optimizer will silently ignore ID values that are not contact IDs (at least, it has in the past, I don't see why that would have changed).
You can put a query result directly into a map without looping through the list.
Thank u very much for replying,
I have tried ur code but it is not updating the task field.
Sorry I got it Thanku very much .My testing was wrong........
Thank u very much..........