You need to sign in to do that
Don't have an account?
Virgilio Ganata
Update Parent (Contact) record based on Task created
Hi,
I am trying to update parent record (Contacts) based on Task
Here is my trigger
So my criteria:
Thank you in advanced
I am trying to update parent record (Contacts) based on Task
Here is my trigger
trigger updateContactFromTask on Task (before insert, before update) { Map<Id,Contact> contactMap = new Map<Id,Contact>(); Set<id> Ids = new Set<id>(); for (Task tk: Trigger.new) { Ids.add(tk.WhoId); } Map<id,Contact> contactMap2 = new Map<id,Contact>([Select Id, Title from Contact Where Id in :Ids]); for (Task t: Trigger.new) if(t.CreatedDate!=system.today()&&Contact.LeadSource != NULL) { Contact l = contactMap2.get(t.WhoId); l.LeadSource = 'Test1234'; contactMap.put(l.id,l); } update contactMap.values(); }
So my criteria:
if(t.CreatedDate!=system.today()&&Contact.LeadSource != NULL)If Task is created Today and Contact LeadSource Not Equal to NULL, This works and sets a Leadsource value, However when I set the LeadSource to another value Say Web. Trigger still fires for update even it has a value. Perhaps something wrong with my trigger.
Thank you in advanced
You could use Trigger.isInsert to identify that Task is created not update.
Thanks
Shashikant
Are you sure that the Contact you are accessing on line 13 is the the Contact associated with WhoId of task? Can you try putting a system.debug to check which Contact record it is referring to?
@Ravi,
Yes, I am sure that the contact is associated with the WhoID creating the task from the Contact record itself.