However it is yielding the error: Error: Compile Error: unexpected token: where at line 14 column 49Have I misunderstood the syntax here? I would really appreciate some help!Thanks, JohnTrigger TaskBefore on Task(before insert, before update){
Map<Id, List<Task>> whoIds = new Map<Id, List<Task>>{};
For (Task t : trigger.new)
If(t.WhoId != null){
List<Task> tasks = whoIds.get(t.WhoId); //this should be t.WhoId (not task.WhoId)
If (tasks == null){
tasks = new List<Task>{};
whoIds.put(t.WhoId, tasks);
}
tasks.add(t);
}
For (Lead ld : [Select Id, Name, MobilePhone where Id in :whoIDs.keySet()])
For(Task t : whoIds.get(ld.id))
t.Mobile__c = ld.Mobile;
For(Contact con : [Select Id, Name, MobilePhone where Id in :whoIds.keySet()])
For(Task t : whoIds.get(con.id))
t.Mobile__c = con.Mobile;
}
8 risposte
Hi John,The reason for the issue is you are missing "from" in the querywrite query like thisFor (Lead ld : [Select Id, Name, MobilePhone From Lead where Id in :whoIDs.keySet()]so that that issue will go.one more thing you need to take here is07 If (tasks == null){08 tasks = new List<Task>{};09 whoIds.put(t.WhoId, tasks);10 }I belive it should be like below otherwise that list will have only one record all the time and will not work for bulk update07 If (tasks == null){08 tasks = new List<Task>();09 }10 whoIds.put(t.WhoId, tasks);let me know, if it helps you or need help :)shiva.sfdc.backup@gmail.com