I am trying to do query on ProcessInstanceStep object,but I keep on getting null values.

I am trying to query comments values for the steps which are Rejected.

I am getting desired ID value of ProcessInstance,but it is not returning any value on ProcessInstanceStep.


for(ProcessInstance  pr : [Select id,ProcessDefinitionId,TargetObjectId from ProcessInstance where TargetObjectId =:'a233B0000001iqu']){

    for(ProcessInstanceStep pri : [Select id,Comments,StepStatus,ProcessInstanceId from ProcessInstanceStep where ProcessInstanceId =:pr.id and StepStatus='Rejected']){

What am I doing wrong here?

  • Did you try the query on workbench? Feb 1, 2017 at 11:58
  • Hey Santanu,I have tried it on developer console and it is working.But I am using the above mentioned code in trigger.Trigger is on Custom Object.So,when Approval step is rejected,Status field on custom object gets updated to Rejected which fires trigger.
    – devsfdc
    Feb 1, 2017 at 12:18
  • Yes,I understand that but since status on object get updated to rejected only when on rejecting the approval step,so I think ProcessInstanceStep record get created before after update trigger gets executed.Please correct me if I am wrong. Actually i am trying fetch comment field value from ProcessInstanceStep and then I will be using that value in emailMessaging.
    – devsfdc
    Feb 1, 2017 at 12:44

1 Answer 1


I am sorry for the misleading comment, I have removed it.

When you have the field update on Final Rejection Actions, you will have the ProcessInstanceStep record in the object trigger. When you have a field update on Approval Steps Action you will not get the rejection comments in the trigger as by the time control reaches the trigger the ProcessInstanceStep records are not created. So move your field update to Final Rejection Action, you should be getting the rejection comments in the trigger.

  • Glad I could help. Feb 1, 2017 at 13:54
  • @devsfdc If this answer addressed your problem, please consider accepting it by clicking on the check mark/tick to the left of the answer, turning it green. This marks the question as resolved to your satisfaction, and awards reputation both to you and the person who answered. If you have >= 15 reputation points, you may also upvote the answer if you wish. There is no obligation to do either.
    – Adrian Larson
    Feb 2, 2017 at 6:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .