You need to sign in to do that
Don't have an account?
Update Approval process status
Hi!
When a user updates one opportunity with approved status, I need to change the opportunity status and modify its approval process process.
For updating the opportunity I have made a workflow rule that works fine, but I am not able of update its approval process status.
My code is below, and it is fired correctly within a trigger:
public static void cambiarEstadoAprobacionOportunidad(Opportunity opp){
List<ProcessInstanceWorkitem> workItemList;
try
{
/* opp.Approval_Status__c='Abierta';
opp.Production_Approval__c=False;
update Opp;*/
}
Catch(DMLException e)
{
opp.addError(e);
}
for (SObject s:[SELECT STATUS from processInstance where TargetObjectId=:opp.Id]){
System.debug('Estado ' + s);
}
List<ProcessInstance> processList = new List<ProcessInstance>();
processList =[SELECT Id, Status FROM ProcessInstance where TargetObjectId=:opp.Id and (Status =: 'Pending' OR Status=:'Aprobado')];
Set<ID> idSet = new Set<ID>();
for(ProcessInstance p : processList)
{
idSet.add(p.Id);
}
workItemList = new List<ProcessInstanceWorkitem>();
workItemList = [Select id from ProcessInstanceWorkitem where ProcessInstanceId in: idSet];
for(ProcessInstanceWorkitem w:workItemList)
{
Approval.ProcessWorkItemRequest pwr = new Approval.ProcessWorkItemRequest();
pwr.setWorkitemId(w.id);
pwr.setAction('Removed');
Approval.ProcessResult pr = Approval.process(pwr);
}
}
Anybody has information about how to solve this problem?
I also would be very interested in receive any tip about how is de approval workflow . Because the information that I have reached is not enough for me.