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

question on upsert task
Having a bit of trouble with this trigger. need some help please...
I want to create a task when a checkListItem is updated. Task should upserted in case existing task for the checklist is not closed. This code is always creating a new task irrespective of existing taks. How to fix this?
I want to create a task when a checkListItem is updated. Task should upserted in case existing task for the checklist is not closed. This code is always creating a new task irrespective of existing taks. How to fix this?
//test trigger AssignCalendarTask on Checklist_Item__c (before update){ List<Task> tasks = [Select id, whatid, status from task where status <>'Closed']; List<Checklist_Item__c> Itms = Trigger.new; for (Checklist_Item__c Itm : Itms) { If (Itm.Active__c && Itm.Responsible__c <> null && Itm.Next_Activity__c <> null) { Task tsk = new Task(whatID = Itm.ID, Ownerid = Itm.Responsible__c, Subject = Itm.Activity_Type__c, Status = 'Assigned', Description = 'This is a system assigned Task.', ActivityDate = Itm.Next_Activity__c, ReminderDateTime=Itm.Next_Activity__c - 3, IsReminderSet=true); tasks.add(tsk); } } upsert tasks; }
I want to create a new task only if there isn't an existing task. For others I want to update task where Checklist_Item__c.Id = Task.whatid.