26 votes

How to check if a record is locked or not in Apex during an approval process

This came out in Winter16. It's part of the approval class Approval.isLocked(recordId) This method can also accept List<Id>, SObject, or List<SObject>. You can also now lock and unlock ...
Shane McLaughlin's user avatar
25 votes
Accepted

Check if a record is in approval process

From Winter16 you can check this using the Approval system class Pass it the Id of a record you want to check if is locked or not: Approval.isLocked(recordId); Make sure you set the class api version ...
sskular's user avatar
  • 583
24 votes
Accepted

Approval lock/unlock with APEX

You need to go to Setup -> Process Automation -> Process Automation Settings (if you use Classic interface - Setup->Create-> Workflows and Approvals -> Process Automation Settings) and ...
kurunve's user avatar
  • 4,289
12 votes
Accepted

Unlock a record which is locked by approval process

As of Winter '16, this is now possible through APEX. (Release Notes) It can be enabled by going to Setup > Create > Workflow & Approvals > Process Automation Settings :
martin's user avatar
  • 12.6k
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,166
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,804
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
  • 487k
7 votes
Accepted

Approve/Reject many Records at once via Apex

I finally got it. Instead of approving each record one at a time, I realized I can put all requests in a list before approving them all at once. Set<Id> accIds = (new Map<Id, Account>([...
Micz Domz's user avatar
  • 685
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,596
6 votes
Accepted

Remove Records From Approval Process In Bulk

Liberal use of Maps should reduce it to this: List<Approval.ProcessWorkitemRequest> requests = new List<Approval.ProcessWorkitemRequest> (); //Get Opps Map<ID, Opportunity> opps : ...
Eric's user avatar
  • 54.1k
6 votes
Accepted

Query user's Items to Approve?

You need to filter on ActorId in addition to ProcessInstance.Status in your query on ProcessInstanceWorkItem. SELECT ProcessInstance.TargetObjectId FROM ProcessInstanceWorkItem WHERE ProcessInstance....
Adrian Larson's user avatar
  • 150k
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
  • 60.9k
5 votes
Accepted

Error when locking a record in BeforeUpdate trigger

Judging by the exception, I'd say that the problem is that you are running this code on an older version of the api that doesn't support the Approval.lock() method. In a different post, I found that ...
martin's user avatar
  • 12.6k
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
  • 150k
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
  • 150k
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
  • 121
4 votes
Accepted

Approval Process Entry Criteria validation messages

The answer is basically NO but you can simulate this by adding a formula field to the top of the standard layout that displays a message This object is not ready for approval submission for reason ...
cropredy's user avatar
  • 70.9k
4 votes
Accepted

Why only one hierarchy field on User object can be used as an approver? This results in additional work for setting up multi-level approval process

If you create a Hierarchy field on the user object, when creating the approval process in step 3 choose that field instead of the manager and it will be available in the approval steps. The issue as ...
Eric's user avatar
  • 54.1k
4 votes
Accepted

N>Help how to change Overall Status Text (Approved,Pending,Rejected)

There is no option to override standard label except overriding standard detail page with custom visualforce page and update the value using jquery or javascript <apex:page standardController="...
Himanshu's user avatar
  • 10.5k
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
  • 70.9k
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.6k
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
  • 70.9k
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

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