function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ramadhar MishraRamadhar Mishra 

Approver comments in apex trigger

I've one custom object on this custom object I've one approval process.

 

in final approval action I've one field update : IsCommentscopy__c==true.

 

I've one before update trigger on same object where I've below code:

 

 
Name
Version
Namespace
Type
Salesforce.com API29.0 Salesforce.com API
Apttus Contract Management6.126Apttus Installed Package
Apttus Echosign Integration1.45Apttus_Echosign Installed Package
DiscoverOrg1.75DiscoverOrg Installed Package
EchoSign12.6echosign_dev1 Installed Package
Eloqua1.3ELOQUA Installed Package
GridBuddy3.24GBLite Installed Package
Indicee Analytics3.8indicee_apps Installed Package
Informatica Data Loader4.0INFA Installed Package
LOOP9.49Loop Installed Package
NetProspex Executive Directory2.5Netprx Installed Package
Nitro for Salesforce1.87nitro Installed Package
Object Console1.9obj_con Installed Package
OrgChartPlus1.23OrgChartPlus Installed Package
Salesforce clients connected apps1.5sf_com_apps Installed Package
Walker PowerInsights1.16Walker_Info Installed Package
Override Log Filters
CategoryLevel
DatabaseNONEERRORWARNINFODEBUGFINEFINERFINEST
WorkflowNONEERRORWARNINFODEBUGFINEFINERFINEST
ValidationNONEERRORWARNINFODEBUGFINEFINERFINEST
CalloutsNONEERRORWARNINFODEBUGFINEFINERFINEST
Apex CodeNONEERRORWARNINFODEBUGFINEFINERFINEST
Apex ProfilingNONEERRORWARNINFODEBUGFINEFINERFINEST
SystemNONEERRORWARNINFODEBUGFINEFINERFINEST
 
trigger SP_copyComments_Trigger on SP_Milestone__c (before update) {
System.debug('SP_copycomments_Trigger called ##');  
String commentsStr='';
  set<id> setmiles=new set<id>();
  for(SP_Milestone__c m : Trigger.New){
    if(m.IsCommentscopy__c){
       setmiles.add(m.id);
    }  
  }
   for (ProcessInstance pi : [SELECT TargetObjectId,
                              ( 
                                 SELECT Id, Comments
                                 FROM Steps                                                               
                              )
                               FROM ProcessInstance
                               WHERE TargetObjectId In :setmiles
                             ])
    {   
     if(pi.steps.size() >0){
       trigger.new[0].BDM_Approver_comments__c=pi.steps[0].Comments ;   
       }   
    }  
}
 
The comments value coming as null. Can any one help.
 
 
Thanks in advanced.
 
Ramadhar Mishra
 
Prashant TiwariPrashant Tiwari
HI Ramadhar,

Just check if the set "setmiles" contains value or it is null.

Thanks, Prashant Tiwari
Ramadhar MishraRamadhar Mishra

trigger SP_copyComments_Trigger1 on SP_Milestone__c (before update) {
System.debug('SP_copycomments_Trigger called ##');  
String commentsStr='';
  set<id> setmiles=new set<id>();
  for(SP_Milestone__c m : Trigger.New){
    if(m.IsCommentscopy__c){
       setmiles.add(m.id);
    }  
  }
  system.debug('setmiles ##'+setmiles);
   for (ProcessInstance pi : [SELECT TargetObjectId,(SELECT Id, Comments FROM Steps) FROM ProcessInstance WHERE TargetObjectId In :setmiles])
    {   
     system.debug('pi.steps ##'+pi.steps);
     if(pi.steps.size() >0){
        for(integer i=0;i<pi.steps.size();i++){
          if(pi.steps[i].comments !=null){
             trigger.new[0].BDM_Approver_comments__c=pi.steps[i].comments;
           }
          }   
       }   
    }  
}
 

I tested in debug log setmiles has one value. it's not null.

 

One of sanbox the above code work fine but not in full copy sanbox. Please if any one has any idea.

 

Thanks,

Ramadhar