You need to sign in to do that
Don't have an account?
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:
|
|
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 ;
}
}
}
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
Just check if the set "setmiles" contains value or it is null.
Thanks, Prashant Tiwari
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