• MarlTroutBum
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies

Hello All, 

 

I am trying to develop a simple IF statement logic based on the outcome of a Task status.  In this case I am looking for all Tasks with a subject line of "Lost Contact Follow Up Call".  Then, depending on what the Task Status is, further action should be taken.

 

 

Here is my code:

trigger SD_Member_Lost_Contact on Task (after insert, after update) {
/*
Automatically update the "Enrollment Progress Status" field, based upon the "Status" field 
of the last Member Task
*/

// Tasks that meet criteria, and new tasks to create
Task[] qualifiedTasks = new Task[0], newTasks = new Task[0];

// Date example with the dt1 variable being set to Today's Date plus 1 day.
Date dt1=DateTime.now().addDays(1).date();
Date rt1=DateTime.now().addDays(1).date();

    
// Map of SD Members
   Map<Id,SD_Member__c> members = new Map<Id,SD_Member__c>();

// Find qualifying tasks
   for(Task record:Trigger.new)
        if(Record.subject =='Lost Contact Follow Up Call' &&
           record.isclosed == True)
           qualifiedtasks.add(record);
    
   // Obtain member ID values
   for(Task record:qualifiedtasks)
        members.put(record.whatid,null);
   
   // If there are any membes to query, do so and pull the following fields.
   if(!members.isempty())
        members.putall([select id, CareCoach__c from SD_Member__c where id in :members.keyset()]);


for(Task record:qualifiedtasks) {
    

    /* IF the task is closed with the following value: Completed – No More Calls this Cycle
    / THEN terminate workflow and no more calls made */
    If (record.Status == 'Completed – No More Calls this Cycle'){}
  
    /* IF the task is closed with the following values:
        Member Hung Up
        Reached Target – Call Later
        Reached Target – No Interest
        Reached Target – Requested Info
        Reached Target – Sent to Care Coach
        Reached Target – Thinking About It
       THEN:
       a) create an immediate task for the Care Coach with the subject "Change Status to In Treatment" 
       and put the following in the comment  “Successful Contact – change status in eOT to in treatment.  
       See call notes for disposition details.”
       b) terminate workflow and now more calls made */
          
      else If (record.Status == 'Member Hung Up'||
               record.Status == 'Reached Target – Call Later'||
               record.Status == 'Reached Target – No Interest'||
               record.Status == 'Reached Target – Requested Info'||
               record.Status == 'Reached Target – Sent to Care Coach'||
               record.Status == 'Reached Target – Thinking About It'){
          Task T1 = New Task(subject='Successful Contact – change status in eOT to in treatment',
                             Status = 'Not Started',
                             whatid = members.get(record.whatid).id,
                             ownerid= members.get(record.whatid).CareCoach__c,
                             ActivityDate=dt1,
                             IsReminderSet=True, 
                             ReminderDateTime=rt1,
                             Description = 'See call notes for disposition details.');
          Insert T1;}
          
      else {
	       SD_Member__c SDM = New SD_Member__c (id=members.get(record.whatid).id, Lost_Contact_Follow_Up__c=True);
           Update SDM;
           }	}
   
    }  

 

 The issue I an having is I do not beleive I have my IF logic correct.  For example: if the Task Status is " Completed – No More Calls this Cycle"

    /* IF the task is closed with the following value: Completed – No More Calls this Cycle
    / THEN terminate workflow and no more calls made */
    If (record.Status == 'Completed – No More Calls this Cycle'){}

 

  then nothing should happen, but for some reason the code instead still executes my ELSE clause:

 

      else {
	       SD_Member__c SDM = New SD_Member__c (id=members.get(record.whatid).id, Lost_Contact_Follow_Up__c=True);
           Update SDM;
           }

 

 Not sure why, but any feedback is welcomed.

 

Regards,

 

MarlTroutBum

 

Hello All, 

 

I am trying to develop a simple IF statement logic based on the outcome of a Task status.  In this case I am looking for all Tasks with a subject line of "Lost Contact Follow Up Call".  Then, depending on what the Task Status is, further action should be taken.

 

 

Here is my code:

trigger SD_Member_Lost_Contact on Task (after insert, after update) {
/*
Automatically update the "Enrollment Progress Status" field, based upon the "Status" field 
of the last Member Task
*/

// Tasks that meet criteria, and new tasks to create
Task[] qualifiedTasks = new Task[0], newTasks = new Task[0];

// Date example with the dt1 variable being set to Today's Date plus 1 day.
Date dt1=DateTime.now().addDays(1).date();
Date rt1=DateTime.now().addDays(1).date();

    
// Map of SD Members
   Map<Id,SD_Member__c> members = new Map<Id,SD_Member__c>();

// Find qualifying tasks
   for(Task record:Trigger.new)
        if(Record.subject =='Lost Contact Follow Up Call' &&
           record.isclosed == True)
           qualifiedtasks.add(record);
    
   // Obtain member ID values
   for(Task record:qualifiedtasks)
        members.put(record.whatid,null);
   
   // If there are any membes to query, do so and pull the following fields.
   if(!members.isempty())
        members.putall([select id, CareCoach__c from SD_Member__c where id in :members.keyset()]);


for(Task record:qualifiedtasks) {
    

    /* IF the task is closed with the following value: Completed – No More Calls this Cycle
    / THEN terminate workflow and no more calls made */
    If (record.Status == 'Completed – No More Calls this Cycle'){}
  
    /* IF the task is closed with the following values:
        Member Hung Up
        Reached Target – Call Later
        Reached Target – No Interest
        Reached Target – Requested Info
        Reached Target – Sent to Care Coach
        Reached Target – Thinking About It
       THEN:
       a) create an immediate task for the Care Coach with the subject "Change Status to In Treatment" 
       and put the following in the comment  “Successful Contact – change status in eOT to in treatment.  
       See call notes for disposition details.”
       b) terminate workflow and now more calls made */
          
      else If (record.Status == 'Member Hung Up'||
               record.Status == 'Reached Target – Call Later'||
               record.Status == 'Reached Target – No Interest'||
               record.Status == 'Reached Target – Requested Info'||
               record.Status == 'Reached Target – Sent to Care Coach'||
               record.Status == 'Reached Target – Thinking About It'){
          Task T1 = New Task(subject='Successful Contact – change status in eOT to in treatment',
                             Status = 'Not Started',
                             whatid = members.get(record.whatid).id,
                             ownerid= members.get(record.whatid).CareCoach__c,
                             ActivityDate=dt1,
                             IsReminderSet=True, 
                             ReminderDateTime=rt1,
                             Description = 'See call notes for disposition details.');
          Insert T1;}
          
      else {
	       SD_Member__c SDM = New SD_Member__c (id=members.get(record.whatid).id, Lost_Contact_Follow_Up__c=True);
           Update SDM;
           }	}
   
    }  

 

 The issue I an having is I do not beleive I have my IF logic correct.  For example: if the Task Status is " Completed – No More Calls this Cycle"

    /* IF the task is closed with the following value: Completed – No More Calls this Cycle
    / THEN terminate workflow and no more calls made */
    If (record.Status == 'Completed – No More Calls this Cycle'){}

 

  then nothing should happen, but for some reason the code instead still executes my ELSE clause:

 

      else {
	       SD_Member__c SDM = New SD_Member__c (id=members.get(record.whatid).id, Lost_Contact_Follow_Up__c=True);
           Update SDM;
           }

 

 Not sure why, but any feedback is welcomed.

 

Regards,

 

MarlTroutBum