Mastering Salesforce Approval Processes Object Model

Arun
3 min readMay 10, 2023

--

In Salesforce, the approval process is a critical feature for managing and maintaining the quality of business processes. Salesforce provides several standard objects to help developers interact with approval processes programmatically. In this blog, we will discuss five essential objects related to approval processes — ProcessInstance, ProcessInstanceHistory, ProcessInstanceNode, ProcessInstanceStep, and ProcessInstanceWorkitem. We will explain these objects in simple language and how to use them effectively in your Salesforce applications.

  1. ProcessInstance:

ProcessInstance represents a specific instance of an approval process. It is created when a record is submitted for approval, and it contains information about the current state of the approval process for that record. In other words, ProcessInstance acts as a snapshot of the approval process’s progress for a particular record.

To query ProcessInstance, you can use the following SOQL query:

SELECT Id, TargetObjectId, Status, ProcessDefinitionId FROM ProcessInstance

Here, TargetObjectId refers to the record submitted for approval, Status indicates the approval process's current status, and ProcessDefinitionId is the ID of the ProcessDefinition (i.e., the approval process definition).

2. ProcessInstanceHistory:

ProcessInstanceHistory represents the history of actions taken on a specific instance of an approval process. This object provides a detailed audit trail of each action taken on an approval process instance, such as approvals, rejections, reassignments, and recalls.

ProcessInstanceHistory does not support querying. Instead, you can use the ProcessInstance object and its related list to retrieve history information for a specific ProcessInstance.

To get the history for a ProcessInstance, you can use the following SOQL query:

SELECT Id, (SELECT Id, StepStatus, CreatedDate, Comments FROM StepsAndWorkitems) 
FROM ProcessInstance

This query retrieves the ProcessInstance ID and related StepsAndWorkitems, which include the history of actions taken on the approval process instance. You will be able to access the StepStatus, CreatedDate, and Comments fields for each step and work item in the history.

3. ProcessInstanceNode:

ProcessInstanceNode represents a node or step in the approval process. This object helps in understanding the approval process’s structure and the sequence of approval steps.

To query ProcessInstanceNode, you can use the following SOQL query:

SELECT Id, ProcessInstanceId, ProcessNodeDefinitionId FROM ProcessInstanceNode

Here, ProcessInstanceId refers to the ProcessInstance ID, and ProcessNodeDefinitionId is the ID of the ProcessNodeDefinition (i.e., the approval step definition).

4. ProcessInstanceStep:

ProcessInstanceStep represents a step within a ProcessInstance and its current status. It provides information about the current state of each approval step within the approval process instance.

To query ProcessInstanceStep, you can use the following SOQL query:

SELECT Id, ProcessInstanceId, StepNodeId, StepStatus, TargetObjectId FROM ProcessInstanceStep

Here, ProcessInstanceId refers to the ProcessInstance ID, StepNodeId is the ID of the ProcessInstanceNode, StepStatus indicates the current status of the step, and TargetObjectId is the record submitted for approval.

5. ProcessInstanceWorkitem:

ProcessInstanceWorkitem represents a work item or pending action for a specific user within a ProcessInstance. It holds information about the approval requests assigned to users as part of the approval process.

To query ProcessInstanceWorkitem, you can use the following SOQL query:

SELECT Id, ProcessInstanceId, ActorId FROM ProcessInstanceWorkitem

Here, ProcessInstanceId refers to the ProcessInstance ID, and ActorId is the ID of the user who is assigned the work item.

In conclusion, this comprehensive guide has provided you with a solid understanding of the Salesforce Approval Process and its related objects, including ProcessInstance, ProcessInstanceHistory, ProcessInstanceNode, ProcessInstanceStep, and ProcessInstanceWorkitem. We have discussed the purpose of each object, how they interact with each other, and how to query them effectively. With this knowledge, you can now harness the power of Salesforce Approval Processes to streamline your organization’s workflows, improve collaboration, and ensure consistent decision-making.

--

--