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
Semira@gmail.comSemira@gmail.com 

Compile Error: Method does not exist or incorrect signature:

Hi, 

Trying to write a method to get Approver from an approval process. Not sure if this is the way to do it. But getting this error on a trigger

trigger UpdateActor on Expense__c (before update) {

    ProcessInstanceStep instance = new ProcessInstanceStep();
  
    Expense__c  exp = new Expense__c();
    exp = [select id from Expense__c where id=:trigger.new[0].Id];
   
    if(trigger.isUpdate && !exp.isEmpty())
    {
        instance = [select id from ProcessInstanceStep where id=:exp.id];
       
        exp.Approved_by__c = instance.ActorId;
    }
   
   

}

If anyone knows anything, please help!
Best Answer chosen by Semira@gmail.com
Semira@gmail.comSemira@gmail.com
ok found it.

List<ProcessInstance> instances = [select Id, Status, TargetObjectId,(select ActorId, Comments, ProcessInstanceId, OriginalActorId, StepStatus from Steps)from ProcessInstance where TargetObjectId =: exp.id limit 10];

That's what I was missing. 

All Answers

sindoorasindoora
Change  this line .exp = [select id from Expense__c where id=:trigger.new[0].Id];
exp = [select id from Expense__c where id=:exp.Id];
Semira@gmail.comSemira@gmail.com
Nope, it saves but when I try to edit the record I get this error now

system.QueryException: List has no rows for assignment to SObject: Trigger.UpdateActor: line 10, column 1

I think it's because ProcessInstanceStep doesn't have id field. So how do I map the ActorId from the record I'm trying to update? 
Semira@gmail.comSemira@gmail.com
ok found it.

List<ProcessInstance> instances = [select Id, Status, TargetObjectId,(select ActorId, Comments, ProcessInstanceId, OriginalActorId, StepStatus from Steps)from ProcessInstance where TargetObjectId =: exp.id limit 10];

That's what I was missing. 
This was selected as the best answer