Skip to main content
All,

I created a trigger ( view below)  that will take values from  the Comments field when an Approver either Approves or Rejects a record, the values in the comment field  will then be inserted in the  Approver_Comment__c long text field located in the  matter__c custom object. However, When I created an email alert for the Final Approval Actions and Final Rejection Actions in the Approval Process, the email does not send me the current information in the Approver_Comment__c in the matter__c custom object, it only sends me the older value. Example if value "Test 1" already exist in the Approver_Comment__c and the approver approves the same record and writes "Test 2" in the Comments fieldd before approving or rejecting the record, after the approver selects the Approve or Reject button, the value "Test 1"  will be send in the email alert , not the value "Test 2". I appreciate the help. I want the most current value in the comments field which in this siutation  is "Test 2" to be sent via the email alert. 

I could appreciate it if someone could assist me on this. 

 

 

trigger TriggerApprover on Matter__c (before update) {

   

       if(trigger.isUpdate){

             List<Matter__c> MatterList =  [Select id,

                                                   (Select Id,

                                                         IsPending,

                                                         ProcessInstanceId,

                                                         TargetObjectId,

                                                         StepStatus,

                                                         OriginalActorId,

                                                         ActorId,

                                                         RemindersSent,

                                                         Comments,

                                                         IsDeleted,

                                                         CreatedDate,

                                                         CreatedById,

                                                         SystemModstamp

                                                    FROM ProcessSteps

                                                ORDER BY CreatedDate DESC)

                                                    From Matter__c

                                                WHERE Id IN : Trigger.new];

 

             if(MatterList.size() > 0){

 

               for(Matter__c mat : MatterList){

             

                for(Matter__c mat1 : Trigger.new) {

                 

                         //check copy comment is true

                         if(mat.id == mat1.id && mat1.Copy_Comment__c) {

 

                           if (mat.ProcessSteps.size() > 0) {

                           

                         mat1.Approver_Comment__c = mat.ProcessSteps[0].Comments;

                         mat1.copy_comment__c = false;

               

                           }

 

                        }

                

                    }

               }

             }  

        } 

    }

 
2 answers
  1. Nov 30, 2015, 7:17 PM
    James,. 

    I tried to modify this trigger, but I was unsuccessful in modifying it. do you have an example of how I can modify this coding? 

    I am using this trigger from approval or rejection of records.

    I followed your advice in step 2, but I am receiving errors, view below.

    trigger TriggerApprover on Matter__c (before update) {

        

           if(trigger.isUpdate){

                 List<Matter__c> MatterList =  [Select id,

                                                       (Select Id,  

                                                             Comments,  

                                                        FROM ProcessSteps

                                                    ORDER BY CreatedDate DESC) 

                                                        From Matter__c

                                                    WHERE ParentId in :Trigger.newMap.keySet()] ];

                 if(MatterList.size() > 0){

                   for(Matter__c mat : MatterList){

                  

                    for(Matter__c mat1 : Trigger.new) {

                      

                             //check copy comment is true

                             if(mat.id == mat1.id && mat1.Copy_Comment__c) {

     

                               if (mat.ProcessSteps.size() > 0) {

                                

                             mat1.Approver_Comment__c = mat.ProcessSteps[0].Comments;

                             mat1.copy_comment__c = false;

                    

                               }

                            }

                     

                        }

                   }

                 }   

            }  

        }

     
0/9000