• Satish9
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
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? 

//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; 
		
}



  • September 22, 2014
  • Like
  • 0
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? 

//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; 
		
}



  • September 22, 2014
  • Like
  • 0