0

approval processworkflow[][1]I have a approval process which is triggering when status of record is pending review. I have created a workflow rule to change the status to expired when the record is passed 14 days from its creation. The workflow is firing and status is changed to expired. But the record is still in approval process and if i approve it is again changed to approved. I am trying to unlock the record when status is changed to expired in trigger handler in before update method. I even tried to remove the process item in after update. Still nothing happened. Should i use before or after update in trigger? Is there anyway i can achieve this.

0

You should use After Update , here's the sample code

List<Approval.ProcessWorkitemRequest> processRequestList = new List<Approval.ProcessWorkitemRequest>(); for(ProcessInstanceWorkItem pIWorkItem : processInstanceWorkItemList){ Approval.ProcessWorkitemRequest workItemRequest = new Approval.ProcessWorkitemRequest(); workItemRequest.setAction('Removed'); workItemRequest.setWorkitemId(pIWorkItem.Id); processRequestList.add(workItemRequest); } if(!processRequestList.isEmpty()){ List<Approval.ProcessResult> processResults = Approval.process(processRequestList); }

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.