You need to sign in to do that
Don't have an account?

Recalling Approval Process
I am trying to execute the following code for recalling an approval process an ends up getting the following error
execution of AfterUpdate caused by: System.DmlException: Process failed. First exception on row 0; first error: INVALID_OPERATION, Illegal transition type:
Approval.ProcessWorkItemRequest pwr = new Approval.ProcessWorkItemRequest();
List<ProcessInstance> procins = new List<ProcessInstance>([select Id from ProcessInstance where Status = 'Pending' and TargetObjectId = :objectId]);
// Retrieve the process work instance id associated to the process instance
List<ProcessInstanceWorkitem> workitem = new List<ProcessInstanceWorkitem>([select Id from ProcessInstanceWorkitem where ProcessInstanceId = :procins[0].id]);
if ((workitem != null) && (workitem.size() > 0))
{
pwr.SetComments(statusToUpdate);
pwr.setWorkItemId(workitem[0].id);
pwr.setAction('Remove');
// Execute process request
Approval.ProcessResult pr = Approval.process(pwr);
}
gbalakri - Try changing this line:
pwr.setAction('Remove');
to this:
pwr.setAction('Removed');
See the docs: http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content%2Fapex_ProcessWorkitemRequest.htm|SkinName=webhelp
All Answers
Hey Girish,
What is "statusToUpdate"? If it's display-text, you need to enclose it in single-quotes.
Only other thought is make sure the Allow submitters to recall approval requests option is selected for the approval process and the code is executed by a sysadmin.
List<ProcessInstanceWorkitem> workitem = new List<ProcessInstanceWorkitem>([select Id, ProcessInstance.TargetObjectId from ProcessInstanceWorkitem where ProcessInstance.TargetObjectId = : objectId and Status = 'Pending']);
Approval.ProcessWorkItemRequest pwr = new Approval.ProcessWorkItemRequest();
if (workitem.size()==1)
{
pwr.setWorkitemId(workitem.id);
pwr.setComments('statusToUpdate');
pwr.setAction('Remove');
Approval.ProcessResult pr = Approval.process(pwr);
}
else{
//result for 2 or more returned?
//result for 0 returned?
}
Hi,
I need to know if Allow submitters to recall approval requests option can be configured via API ? because I do the process from API. can u tell me the detail how to set this option ? thanx..
regards,
edwin
I am attemping the same thing and I used your example. However, I get an error on this line:
pwr.setWorkitemId(workitem.id);
error: Initial term of field expression must be concrete SObject: LIST: SOBJECT: ProcessInstanceWorkitem
What does this mean?
gbalakri - Try changing this line:
pwr.setAction('Remove');
to this:
pwr.setAction('Removed');
See the docs: http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content%2Fapex_ProcessWorkitemRequest.htm|SkinName=webhelp
Thanks for this! I too was using 'Remove' instead of 'Removed'.
Strikes me as a bit odd that it's called 'Removed' anyway, rather than 'Recall', but hey - it works :)
Note: 'Removed' will translate to 'Recalled' in Approval Status, as you see in the system.
Thank you gbalakri and jlo.
I have added a verification of null for procins before accesing the [0] element of it and also I have made statusToUpdate as a parameter so we can send it as a String from a Process Builder for example.
Regards,
Fabio
I have added (https://rhotels.ae/en/ramada-hotel-suites-by-wyndham-dubai-jbr.html)a confirmation of invalid for procins prior to accesing the [0] component of it and furthermore I have created statusToUpdate as a boundary so we can send it as a String from a Process Builder for instance.
thanks for sharing the Recalling Approval Process but I have tried for Robotic screwdriving systems (https://www.calvindude.com) but it did not work accordingly, It shows an error in execution. May I know what is the reason behind that..?
thanks
Sacramento Bail (https://www.atlantisbailbonds.net/) must be posted by a Sacramento Bail Bonds Agent (https://www.atlantisbailbonds.net/)who knows How Bail Bonds Work Sacramento (https://www.atlantisbailbonds.net/) and can offer a Bail Payment Plan in Sacramento (https://www.atlantisbailbonds.net/). Fast Bail Sacramento (https://www.atlantisbailbonds.net/) can be obtained from someone who provides 24 Hour Bail Bonds Sacramento (https://www.atlantisbailbonds.net/).
This information has inspired me to take online courses and exams to better myself. I currently work in an auto repair shop in Rancho Cordova (https://autorepairshopranchocordova.com/). As an apprentice, I am learning brake repair, (https://autorepairshopranchocordova.com/) automobile electrical repair, (https://autorepairshopranchocordova.com/) transmission repair (https://autorepairshopranchocordova.com/) and suspension repair, (https://autorepairshopranchocordova.com/) but I need more formal education to get a better job.