1

I have a custom object that has approval process on it. When I'm submitting something for approval I provide some comments, and when I'm approving/rejecting, I'm also providing some comments. I wanted to capture those comments with trigger and store them on a record, and I have a problem - when I approve/reject, everything works fine both in beforeUpdate and afterUpdate, but in case of submitting for approval, the trigger doesn't see this ProcessInstanceStep yet. Is there a way to get this comment synchronously?

0

*I wanted this to be a comment, but I can not do that. *I am a novice, but this looked familiar..

I have a trigger like this that collects comments from the approver, and it has been a while since I was working on it, but I was looking through and: I have my approval process check a box (Copy1) on the object during the first approval step. My trigger then jumps in and grabs the comment from the approver and saves it to the record then unchecks that box. If yours is similar, maybe if the triggering box was set earlier, it could capture the submitters comments?

trigger RIMPullComments on RIM__c (before update) {

       if(trigger.isUpdate){
             List<RIM__c> RIMList =  [Select id,
                 (Select Id, IsPending,ProcessInstanceId,TargetObjectId,StepStatus,OriginalActorId, 
                  ActorId,RemindersSent,Comments,IsDeleted,CreatedDate,CreatedById,SystemModstamp 
                  FROM ProcessSteps WHERE Comments<>null ORDER BY CreatedDate ASC) 
             From RIM__c
             WHERE Id IN : Trigger.new];
             if(RIMList.size() > 0){
               for(RIM__c r : RIMList){
                for(RIM__c RIM1 : Trigger.new) {
                         //check copy comment is true
                         if(r.id == RIM1.id && RIM1.Copy1__c) {
                           if (r.ProcessSteps.size() > 0) {
                         RIM1.Approval_Comments__c = r.ProcessSteps[0].Comments;
                         RIM1.Copy1__c = false;
                 }}}}
             }   
        }  
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.