You need to sign in to do that
Don't have an account?
Janno Rip
Insert Value on Task from linked Account
Hello Developers,
I have the following trigger which pulls data (Leadevent_Kategorie__c) from the lead / contact and writes it after creation/insert on the task (tk.Vertriebsaktion__c).
I have the following trigger which pulls data (Leadevent_Kategorie__c) from the lead / contact and writes it after creation/insert on the task (tk.Vertriebsaktion__c).
trigger UpdateLeadeventKategorieTask on Task (before insert) { Set<Id> leadId = new Set<Id>(); Set<Id> contactid = new Set<Id>(); for(Task t : Trigger.new){ if(t.WhoId != null){ String s1 = t.WhoId; if(s1.left(3) == '00Q'){ leadId.add(t.whoId); } else if(s1.left(3) == '003'){ contactId.add(t.whoId); } } } Map<Id,Lead> leadMap = new Map<Id,Lead>([Select Id, Leadevent_Kategorie__c From Lead Where Id In : leadId]); Map<Id,Contact> contactMap = new Map<Id,Contact>([Select Id, Leadevent_Kategorie__c From Contact Where Id In : contactId]); for(Task tk: Trigger.New){ if(tk.Vertriebsaktion__c == null) { if(!leadMap.isEmpty() && leadMap.containsKey(tk.WhoId)){ tk.Vertriebsaktion__c = leadMap.get(tk.WhoId).Leadevent_Kategorie__c; } else if(!contactMap.isEmpty() && contactMap.containsKey(tk.WhoId)){ tk.Vertriebsaktion__c = contactMap.get(tk.WhoId).Leadevent_Kategorie__c; } } } }This works just perfect. But what would need in addition is the scenario where a task is neither linked to a lead
if(t.WhoId != null){ String s1 = t.WhoId; if(s1.left(3) == '00Q'){nor to a contact
else if(s1.left(3) == '003'){ contactId.add(t.whoId);
but only to an account. So in fact 'WhoId' would be emtpy and 'WhatId' would begin with '001'.
Where and how can I add this condition?
Greetings and Thanks in Advance!
Jan
Try below code.
Hope this helps, Mark as solved if it did.
Thanks,
Sarvani
All Answers
Try below code
Hope this helps,
Thanks,
Sarvani
I tried your code and added my "Do something" to it, according to the structure it already had. I did the new code in "bold":
But I am getting: Error: compilation errorr: Missing ';' at '{' in row 17, column 51
Try below code.
Hope this helps, Mark as solved if it did.
Thanks,
Sarvani