Skip to main content
12 votes

How to query all active approval processes

you can do it by means of Process.. sobjects: ProcessDefinition (Represents the definition of a single approval process.) ProcessInstance (Represents an instance of a single, end-to-end approval ...
Oleksandr Berehovskyi's user avatar
10 votes

Recall approval process by apex

By design, Approval Processes only allow either a System Administrator and/or the Initial Submitter to recall the submission. Per Salesforce documentation: However, to answer your question How can I ...
Doug Ayers's user avatar
  • 4,196
10 votes
Accepted

SOQL to pull out Approval History records

You can Query ProcessInstance and get related details from child records. Here is sample code for you. for (Account a : [SELECT Id,(SELECT ID FROM ProcessInstances ORDER BY CreatedDate DESC) FROM ...
Tushar Sharma's user avatar
9 votes
Accepted

Parallel Approvers

See Create an Approval Step. In step 10 it says: Require unanimous approval from all selected approvers. The record is only approved if all of the approvers approve the request. The approval ...
Mr.Frodo's user avatar
  • 5,812
8 votes
Accepted

How to deploy Approval processes using ANT migration tool?

When you add fullName to a package.xml, the metadata API assumes you're trying to insert/update a package instead of deploying unpackaged metadata. You must not specify fullName when deploying ...
sfdcfox's user avatar
  • 497k
7 votes

Invalid type: StepsAndWorkitems

StepsAndWorkitems is not a type, it is a child relationship name for ProcessInstanceHistory, so type should be ProcessInstanceHistory and not StepsAndWorkitems. Excerpt from the salesforce ...
Vijay Ganji's user avatar
  • 6,656
6 votes
Accepted

How can a trigger be written so that it fires when a record is approved?

Nope, triggers themselves can't be set to listen for a change on a specific field. Triggers can be set to fire on before/after insert, update, delete, and undelete events, and will always fire on ...
Derek F's user avatar
  • 62.7k
5 votes

how to create the object processInstance in test class

Take a look at this Apex Approval Processing Example. You should use the Approval.Process method (documentation). public class ApprovalExample { void submitAndProcessApprovalRequest() { /...
Adrian Larson's user avatar
  • 151k
5 votes

How can a trigger be written so that it fires when a record is approved?

The approval process cannot directly trigger the apex trigger. You will need to create a field (e.g. checkbox) that is checked by the approval step in the approval process. Then start a trigger ...
Guy Clairbois's user avatar
5 votes
Accepted

Check isEmpty OR Catch ListException?

The main problem with your current try/catch is that an empty catch block is a major anti-pattern. It's not a habit you want to pick up. In terms of reliability, the behavior of this pattern will be ...
Adrian Larson's user avatar
  • 151k
5 votes

Why do we use setProcessDefinitionNameOrId() in ProcessSubmitRequest Class?

This method is used to specify that current record will be submitted to which procress. If one object have multiple approval process and many of them does not match criteria then you will get an ...
Tushar Sharma's user avatar
5 votes
Accepted

Approval process and entry criteria

Why did the process continue into Approval process 1 even though the gender was female? Ans: Approval process runs based on the defined process orders. So, first it will enter process order 1 and ...
Santanu Boral's user avatar
5 votes
Accepted

What is the order of execution for the final approval actions in a standard approval process?

They will not be guaranteed to fire in the order you see listed, however this will still work out for you. In Considerations for Field Update Actions that covers creating field updates for workflow ...
Kris Goncalves's user avatar
4 votes

Insufficient privileges message shown for approval page

The answer above is not correct. You don't need edit permission to the record in order to approve it - only read permission as stated in sales force documentation: https://help.salesforce.com/...
ASGJim's user avatar
  • 131
4 votes

The record couldn’t be saved CANNOT_EXECUTE_FLOW_TRIGGER

If anyone is still looking for a better answer in this thread... here you go. You might get this error if the SObject (that you're inserting ) has an active Process Builder that expects certain ...
Sekar Ramamurthy's user avatar
4 votes
Accepted

Press button from apex trigger

Put a soft alert on the page using a conditional image formula IF (NOT(IsApproved__c) && HasDiscountExceedingGuidelines__c , IMAGE("/img/samples/flag_red.gif" , 'Red' ,12,12) & ...
cropredy's user avatar
  • 72.1k
4 votes
Accepted

'Unlock' button in Salesforce Approval process?

First of all, you would only see the Locked/Unlock button if you're an administrator for that record (I'm pretty certain that would mean having Modify All on the object in your profile or a Permission ...
pchittum's user avatar
  • 19.8k
4 votes
Accepted

Internal Server Error (gack) Submit for Approval - VF Email Templates

Fortunately, SFDC Help had the clue, pointing me to an issue with the VF email template Prior to bug report, Submit for Approval was working fine VF template had markup like below: <apex:...
cropredy's user avatar
  • 72.1k
4 votes
Accepted

Ordering approval process history items by CreatedDate DESC doesn't give the correct order of execution

I've been able to make it work with the following query: private Map<Id,ProcessInstance> getProcessHistory(Id objectId){ return new Map<Id,ProcessInstance>([SELECT ...
Fernando Gavinho's user avatar
4 votes
Accepted

How to find in Salesforce that the Oppotunity is in submit for approval process?

If you do the bare minimum in setting up an Approval Process, the only thing that submitting a record to that Approval Process will do is lock your record. In other words, there are no fields on your ...
Derek F's user avatar
  • 62.7k
4 votes
Accepted

Record Lock release

The Apex Approval class has a variety of methods to check if a record is isLocked, to unlock a record and to lock a record. So you should be able to write a trigger that uses these methods to ...
Keith C's user avatar
  • 136k
4 votes

Check isEmpty OR Catch ListException?

Exceptions are meant to be a rare occurrence, an "exception to the normal flow." I would state that a ListException is always a logic bug in the code, and should not be handled as "business as usual." ...
sfdcfox's user avatar
  • 497k
4 votes
Accepted

Approval Process - how to get the value of the approval comment while in the parent object's trigger?

So, not a pretty solution, but it works. 1) Make a field update from the approval process to the parent object, making sure it causes a re-evaluation of workflows (there is a checkbox on the field ...
Kirill Yunussov's user avatar
4 votes
Accepted

New to coding, can't get my trigger code to work

This should do it, I eyeballed it but any mistakes should be minimal. Check out this to learn more about Approvals. I wrote this assuming that your approvals checkbox is being update correctly. ...
EricSSH's user avatar
  • 4,344
4 votes
Accepted

Lock and Unlock opportunity object during approval process

In your class declaration are you applying the sharing rules? If you try to disable them to ensure that the rules for the current user are not applied with the keyword "without". In this way: public ...
Diego's user avatar
  • 56
4 votes
Accepted

Bulkify Apex Approval.ProcessSubmitRequest

Note that the Approval.process method has a signature which accepts a List<Approval.ProcessRequest>: public static Approval.ProcessResult [] process(Approval.ProcessRequest[] approvalRequests)...
Adrian Larson's user avatar
  • 151k
4 votes
Accepted

User hits record lock error despite class without sharing

Without Sharing only lets you access records they wouldn't normally have access to. Record Locks are still going to be an issue. You should look at the help on sharing in Apex. https://developer....
Daniel Hoechst's user avatar
4 votes

Approval Process : What will happen if approver is inactive

While submitting for approval to an inactive user you will get an error message. operation performed with inactive user For freezed accounts you will be able to submit for approval though.
Nagendra Singh's user avatar
3 votes
Accepted

Replacing save button with submit for approval in the edit page

You can't replace the "Save" button like that. If you absolutely need something that automatically sends a record for approval, I recommend you write a trigger that manually does that on any save. ...
Sebastian Kessel's user avatar
3 votes

Recall approval process by apex

A more modern approach (though similar in principle to Doug's answer) is to use Platform Events. In my code I checked the approval and fired like this: if(thisApprovalRequest.approvalAction == '...
Aidan's user avatar
  • 13.8k

Only top scored, non community-wiki answers of a minimum length are eligible