title: Updating Custom Object from Activity Process Instance Object in Salesforce
body: <p>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.</p>
  
  <p>Any help or suggestions would be appreciated.</p>
  
  <p>trigger update_Provisioner on Service_Request__c (before update) {</p>
  
  <pre><code>for(Service_Request__c sr:Trigger.new){
  
  List &lt;ProcessInstance&gt; pi = [SELECT Id, CreatedDate from ProcessInstance where TargetObjectId = :sr.Id ORDER BY CreatedDate DESC limit 1];
  List &lt;ProcessInstanceStep&gt; op = [SELECT Id, StepStatus, ActorId, OriginalActorId, CreatedDate FROM ProcessInstanceStep where ProcessInstanceId = :pi[0].Id ORDER BY CreatedDate DESC limit 1];
  
  
          if(op.size()&gt;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;
  
            }       
  
  }
  </code></pre>
  
  <p>}</p>