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
raj kiranraj kiran 

Not getting the ProcessInstance Id for Approval Process ?????

hi,
   I wrote a trigger in which i am simply checking the id = null or not.....
The scenario is :
1) on lead object I have created 4 steps approval process
2) when a record is inserted then user has to click on the approval process "submit " button .
3) when i click this button then in processinstance object a record will be created with the targetobject id with the lead record and there is a field in lead object which get updated for every approval process .....

now when i check the record in workbench then it's showing it but when i am trying to get the same record thro' trigger then it's showing me null record...

here is the code :
trigger leadSubmitForApproval on lead (after update) {
set<id> setleadid=new set<id>();
 for (lead opp: Trigger.New)
{       
  if (trigger.oldmap.get(opp.id).Status != opp.Status &&  opp.RecordTypeID == '01290000001AJWz')
 {            
    setleadid.add(opp.id);
}    
}


for(ProcessInstance obj : [select  id,SystemModstamp from ProcessInstance
                where targetobjectid in : setleadid
                and CompletedDate = Null AND  Status = 'Pending' ])

        System.debug('Submitted for approval successfully: '+obj.id);      
}
}

output for the first time : Rows: 0  // I am nt getting the record only when i run it for first time
so , can anyone help me on this.
I tried my best to make  the scenario clear .

thanks in advance..........
Sforce.NinjaSforce.Ninja
I think you are stuck in context. Not 100% sure but maybe someone else can confirm.

Is there a field update action for Initial submission action?



 
raj kiranraj kiran
Sforce.Ninja,

Thanks for your reply. yes there is an status field updated on initial submission action.