This trigger pulls values from the Process Instance object, stores them in a list, and updates a field on the custom object. The problem is that in order to see the value, the user must update and save the record. Normally I'd add an 'After Update' trigger on the Process Instance object, but that is not allowed by Salesforce.
Any help or suggestions would be appreciated.
trigger update_Provisioner on Service_Request__c (before update) {
for(Service_Request__c sr:Trigger.new){
List <ProcessInstance> pi = [SELECT Id, CreatedDate from ProcessInstance where TargetObjectId = :sr.Id ORDER BY CreatedDate DESC limit 1];
List <ProcessInstanceStep> op = [SELECT Id, StepStatus, ActorId, OriginalActorId, CreatedDate FROM ProcessInstanceStep where ProcessInstanceId = :pi[0].Id ORDER BY CreatedDate DESC limit 1];
if(op.size()>0){
//System.debug('Hello'+sr.Provisioner__c+' '+op[0].StepStatus + ' '+ op[0].ActorId + ' ' +op[0].OriginalActorId + ' '+ op[0].CreatedDate);
sr.Provisioner__c = op[0].ActorId;
}
}
}