
9 件の回答

Ok. I now have this working. Code below. Thanks for all of your help. Much appreciated.trigger LeadTrigger on Task (before insert, before update) { List<Id> leadIds=new List<Id>(); for(Task t:trigger.new) { if(t.Status=='Completed') { if(t.whoId != null && String.valueOf(t.whoId).startsWith('00Q')==TRUE) //check if the task is associated with a lead { leadIds.add(t.whoId); }//if 2 }//if 1 }//for map<id,Lead> LeadtaskMap = new map<id,Lead>([SELECT Id, Description, Status FROM Lead WHERE Id IN :leadIds AND IsConverted=FALSE]); for(Task tsk:trigger.new) { if(LeadtaskMap.keyset().contains(tsk.whoid)) { if(tsk.Status == 'Completed' && tsk.Subject == 'Make contact with Lead') { LeadtaskMap.get(tsk.whoid).Status = 'Contacted'; } // System.debug('1 condition:' + LeadtaskMap.get(tsk.whoid).Description == NULL); // System.debug('2 condition:' + tsk.Status == 'Completed'); // System.debug('3 condition:' + tsk.Subject == 'Make contact with Lead'); // System.debug('task:' + tsk); Else if(LeadtaskMap.get(tsk.whoid).Description == Null && tsk.Status == 'Completed' && tsk.Subject == 'Qualify Lead') { tsk.adderror('Task cannot be completed until the following fields have been populated: Description'); } Else { LeadtaskMap.get(tsk.whoid).Status = 'Qualified'; } } } List<Lead> leadList = LeadtaskMap.values(); update leadList; }