• JFowler
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 5
    Replies
I'm working on a trigger that will send an email to the user who created a task when the task is closed by a user other than the one that created it, and am running into some trouble with the code. I'm getting an unexpected token error (unexpected token: '{') on this piece: if(!mails.isEmpty(){

Can someone possibly help out with what might be going wrong? Also, do you know how I can limit this to be only being tasks assocaited to my custom object, Closing__c? Thanks for your help!

trigger Task_Email_Trigger on Task (after insert, after update){
    List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>(); 
    
    for(Task t : Trigger.new){
        if(t.CreatedById != t.OwnerId && t.Status == 'Completed'){
            
            EmailTemplate et=[Select id from EmailTemplate where DeveloperName='Task_Complete_Template'];
            mail.setTemplateID(et.Id);
            mail.setTargetObjectID(t.CreatedById);
            mail.saveAsActivity = false;
            Messaging.SingleEmailMessage = new Messaging.SingleEmailMessage();
            
            mails.add(mail); 
             
        }
        
    }
    if(!mails.isEmpty(){
        Messaging.sendEmail(mails);
    
    }
    
}
I'm working on a trigger that will send an email to the user who created a task when the task is closed by a user other than the one that created it, and am running into some trouble with the code. I'm getting an unexpected token error (unexpected token: '{') on this piece: if(!mails.isEmpty(){

Can someone possibly help out with what might be going wrong? Also, do you know how I can limit this to be only being tasks assocaited to my custom object, Closing__c? Thanks for your help!

trigger Task_Email_Trigger on Task (after insert, after update){
    List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>(); 
    
    for(Task t : Trigger.new){
        if(t.CreatedById != t.OwnerId && t.Status == 'Completed'){
            
            EmailTemplate et=[Select id from EmailTemplate where DeveloperName='Task_Complete_Template'];
            mail.setTemplateID(et.Id);
            mail.setTargetObjectID(t.CreatedById);
            mail.saveAsActivity = false;
            Messaging.SingleEmailMessage = new Messaging.SingleEmailMessage();
            
            mails.add(mail); 
             
        }
        
    }
    if(!mails.isEmpty(){
        Messaging.sendEmail(mails);
    
    }
    
}

I am trying to create a trigger that will fire off a email to a user when the assign to person completes their activity.

 

how do i add a email template to this trigger below?

 

trigger Trigger_Request_CompletedAfterInsertAfterUpdate on Task (after insert, after update)
 {
    
 
   Task[] completedTasks = Trigger.new;
   for(Task t : completedTasks){
      if(t.RecordTypeId == '01270000000UGMe' && t.Status=='Completed'){
         Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
        
      }
   }
}

 

  • July 22, 2011
  • Like
  • 0