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
trublutrublu 

API to recall approval request

Does anyone know the API for recalling approval request ?
 
I have setup Approval process in Salesforce. I would like to recall an existing approval request through API instead of logging into Salesforce and clicking Recall Approval Request button.
 
I tried looking into process, but it doesnt say one can RECALL an approval. Since we can recall thru the UI, there should probably be a way to do it thru the API?
 
Thanks a lot.


Message Edited by trublu on 07-14-2008 06:13 PM
werewolfwerewolf
Have a look at the Approvals sample in the Apex Language reference.  You just have to change the action on the workitem to 'Remove'.

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_process_example.htm

So like:

// Instantiate the new ProcessWorkitemRequest object and populate it
Approval.ProcessWorkitemRequest req2 = new Approval.ProcessWorkitemRequest();
req2.setComments('Removing request.');
req2.setAction('Remove');

trublutrublu

Thank you for your response.

My question with this approach is that the Approval object only represents the approval request for a Contract.

So, if I set up an approval workflow for Opportunity, how do I instantiate the new ProcessWorkitemRequest object and populate it? How do I get the list of workitemids associated with an object - Opportunity in this case?
 
Also, does Remove indicate that an approval request is recalled by the approvee, or an approval decision is recalled by an approver?
 
Thank you very much for your help again.
 
====================================
ProcessWorkitemRequest Arguments
NameTypeDescription
action string For processing an item after being submitted for approval, a string representing the kind of action to take: Approve, Reject, or Remove. Only system administrators can specify Remove.
nextApproverIds ID[] If the process requires specification of the next approval, the ID of the user to be assigned the next request.
comment string The comment to add to the history step associated with this request.
workitemId ID The ID of the ProcessInstanceWorkitem that is being approved, rejected, or removed.
werewolfwerewolf
Huh?  In the example I linked to it shows the approval objects being used with an Account.  You can use them with any object that is eligible for approvals.  It's the same process for any object, you just have to setObjectId on the Approval.ProcessSubmitRequest.
werewolfwerewolf
I don't think you can remove an approval decision, you can only remove an approval request.
trublutrublu

That's a good news....

So the description about Approval in the API is incorrect then? Please confirm. I appreciate it!!!

http://www.salesforce.com/us/developer/docs/api/index.htm

werewolfwerewolf
That describes a completely different Approval object that is retained for backward compatibility.  Look up "Approval processes" in the Apex Language Reference instead:

http://www.salesforce.com/us/developer/docs/apexcode/index.htm
trublutrublu

werewolf,

"It's the same process for any object, you just have to setObjectId on the Approval.ProcessSubmitRequest."

Actually, ProcessSubmitRequest is for submitting objects to the approval process, right? Then how about ProcessWorkitemRequest? How do I get the workitemids associated with a parent object (e.g. Opportunity)?

Thank you.

====================================

ProcessWorkitemRequest Arguments

NameTypeDescription
action string For processing an item after being submitted for approval, a string representing the kind of action to take: Approve, Reject, or Remove. Only system administrators can specify Remove.
nextApproverIds ID[] If the process requires specification of the next approval, the ID of the user to be assigned the next request.
comment string The comment to add to the history step associated with this request.
workitemId ID The ID of the ProcessInstanceWorkitem that is being approved, rejected, or removed.

 

 

trublutrublu

werewolf,

I am sorry that I missed the following link that you provided:

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_process_example.htm

I got it now!!!
 
THANK YOU!!!


Message Edited by trublu on 07-16-2008 07:44 PM
werewolfwerewolf
Yes, you can find them in the Process tables -- in your case you'd want to query ProcessInstanceWorkitem where ProcessInstance.TargetObjectId = whatever ID you're looking for.
trublutrublu
werewolf,
 
So to recall after the fact - a few days/hours after submitting the approval request. Does the code below make sense? Please advise if I am mistaken!
 
THANK YOU VERY MUCH!!!
 
//STEP 1 - JUST TO CREATE THE PROCESSRESULT OBJECT (IM NOT SURE ABOUT THIS)
// Create an approval request for the account (STRANGE TO ME, DOES IT MAKE SENSE?)
Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest();
req1.setObjectId(anAccountId);

// Submit the approval request for the account
Approval.ProcessResult result = Approval.process(req1);

// First, get the ID of the newly created item
List<Id> newWorkItemIds = result.getNewWorkitemIds();
//STEP 2 - UPDATE THE WORKITEMS WITH REMOVE ACTION.
// Instantiate the new ProcessWorkitemRequest object and populate it
Approval.ProcessWorkitemRequest req2 = new Approval.ProcessWorkitemRequest();
req2.setComments('Recalling request.');
req2.setAction('Remove');
req2.setNextApproverIds(new Id[] {UserInfo.getUserId()});
// Submit the request for approval
Approval.ProcessResult result2 =  Approval.process(req2);


Message Edited by trublu on 07-16-2008 07:55 PM
werewolfwerewolf
Not quite.  You have to query the work items first, like

Select p.Id, p.ProcessInstanceId, p.ProcessInstance.TargetObjectId from ProcessInstanceWorkitem p where p.ProcessInstance.TargetObjectId = <my id>

Then you can create an Approval.ProcessWorkitemRequest object, call setWorkitemId on it to the ID you just got from that query, and now you're golden, you can do with it as you please.
trublutrublu
werewolf,
 
in your case you'd want to query ProcessInstanceWorkitem where ProcessInstance.TargetObjectId = whatever ID you're looking for.
I am sorry... I am not finding any sample code dealing with ProcessInstanceWorkitem or ProcessInstance...
I would sincerely appreciate it if you could help me out here as this is the last step toward what I need to acomplish...
 
I just need the code to retrieve workitemids based on a parent id like account id... The code that I showed you in my previous doesn't seem to make sense, so I guess I really need to work with ProcessInstanceWorkitem like you mentioned...
 
Thank you again!
trublutrublu

werewolf,

Just read your latest response... so I need to use sql to actually retrieve the workitemids from the table?

Thank you very much!!!!!!



Message Edited by trublu on 07-16-2008 08:13 PM
werewolfwerewolf
Yes, it's a simple SOQL statement.  There may not be sample code for this in particular but embedding SOQL code in your Apex is trivial.  When you've got it working you should post it here so other people can use it too.