Approval Process(批准过程)简介

批准过程是一个复杂的业务过程。详细的内容可以参考官方文档。

英文版

中文版

官方trailhead模块

在Apex中调用Approval Process

在Apex中可以使用以下类对Approval Process进行操作:

  • ProcessInstance:可以用来查询或遍历Approval Process过程。
  • ProcessInstanceHistory:只读对象,不能直接被SOQL查询。代表了Approval Process过程的所有步骤和相关的状态为“pending”的请求。
  • ProcessInstanceStep:代表了Approval Process过程的一个步骤。
  • ProcessInstanceWorkitem:代表了Approval Process过程相关的状态为“pending”的请求。

在Apex中可以使用SOQL对ProcessInstance进行查询,而对于其他三个类的查询一般是作为对ProcessInstance查询的子语句来进行。

SELECT Id, (SELECT Id, StepStatus, Comments FROM Steps)
FROM ProcessInstance

上面这段代码可以查询Approval Process过程的Id,并查询其包括的步骤的各个属性。

SELECT Id, (SELECT Id, ActorId, ProcessInstanceId FROM Workitems)
FROM ProcessInstance

上面这段代码可以查询Approval Process相关的状态为“pending”的请求(Workitems)。

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

上面这段代码可以查询Approval Process过程的历史记录。

SELECT Id, ActorId, ProcessInstanceId
FROM ProcessInstanceWorkitem
WHERE ProcessInstanceId = 'XXXX'

上面这段代码可以查询和某个Approval Process的相关的所有状态为“pending”的请求。

官方代码示例

以下代码拷贝自官方文档,作为使用Approval Process的示例:

public class TestApproval {
void submitAndProcessApprovalRequest() {
// Insert an account
Account a = new Account(Name='Test',annualRevenue=100.0);
insert a; User user1 = [SELECT Id FROM User WHERE Alias='SomeStandardUser']; // Create an approval request for the account
Approval.ProcessSubmitRequest req1 =
new Approval.ProcessSubmitRequest();
req1.setComments('Submitting request for approval.');
req1.setObjectId(a.id); // Submit on behalf of a specific submitter
req1.setSubmitterId(user1.Id); // Submit the record to specific process and skip the criteria evaluation
req1.setProcessDefinitionNameOrId('PTO_Request_Process');
req1.setSkipEntryCriteria(true); // Submit the approval request for the account
Approval.ProcessResult result = Approval.process(req1); // Verify the result
System.assert(result.isSuccess()); System.assertEquals(
'Pending', result.getInstanceStatus(),
'Instance Status'+result.getInstanceStatus()); // Approve the submitted request
// First, get the ID of the newly created item
List<Id> newWorkItemIds = result.getNewWorkitemIds(); // Instantiate the new ProcessWorkitemRequest object and populate it
Approval.ProcessWorkitemRequest req2 =
new Approval.ProcessWorkitemRequest();
req2.setComments('Approving request.');
req2.setAction('Approve');
req2.setNextApproverIds(new Id[] {UserInfo.getUserId()}); // Use the ID from the newly created item to specify the item to be worked
req2.setWorkitemId(newWorkItemIds.get(0)); // Submit the request for approval
Approval.ProcessResult result2 = Approval.process(req2); // Verify the results
System.assert(result2.isSuccess(), 'Result Status:'+result2.isSuccess()); System.assertEquals(
'Approved', result2.getInstanceStatus(),
'Instance Status'+result2.getInstanceStatus());
}
}

Approval Process 在 Apex 中的使用的更多相关文章

  1. 在Salesforce中创建Approval Process

    在Salesforce中可以创建Approval Process来实现审批流程的功能,实际功能与我们常说的Workflow很相似,具体的设置步骤如下所示 1):选择对应的Object去创建对应的App ...

  2. salesforce 零基础开发入门学习(九)Approval Process 介绍

    在阅读此篇文章前,可以先参考阅读一个前辈总结的关于Approval Process的操作.以下为参考的链接: http://www.cnblogs.com/mingmingruyuedlut/p/37 ...

  3. Scoring and Modeling—— Underwriting and Loan Approval Process

    https://www.fdic.gov/regulations/examinations/credit_card/ch8.html Types of Scoring FICO Scores    V ...

  4. salesforce零基础学习(八十七)Apex 中Picklist类型通过Control 字段值获取Dependent List 值

    注:本篇解决方案内容实现转自:http://mysalesforceescapade.blogspot.com/2015/03/getting-dependent-picklist-values-fr ...

  5. Apex 中 PageReference 的使用

    PageReference类的作用 PageReference类位于Apex的System命名空间下.它可以用来在Apex代码中将页面跳转到指定的位置.在开发的时候,我们也可以向其中添加任意的参数. ...

  6. 在 Apex 中得到 sObject 的信息

    Salesforce 的数据模型是基于 sObject 的.在 Apex 中,所有的标准对象.自定义对象都是继承自 sObject 的. 关于在 Apex 中得到 sObject 的信息,我们要基于两 ...

  7. Apex 中文件夹相关的单元测试

    Salesforce 中的文件夹 在 Salesforce 中,我们可以建立各种文档.报表.仪表板.电子邮件模板等.它们都被保存在相应的文件夹中. Salesforce 的后端将这些文件夹保存为 Fo ...

  8. 在 Apex 中使用合并统计查询

    SOQL 中的合并统计查询 在 SOQL 中,我们可以使用一系列函数来进行合并统计查询.它们的功能和标准 SQL 中的 SUM(),COUNT() 等函数类似. 官方文档 Apex 中使用合并统计查询 ...

  9. 在Apex中使用sObject

    sObject对象的定义 Salesforce中的标准对象或自定义对象在Apex中使用时被称作"sObject".sObject对象的一个实例相当于Salesforce中的一条记录 ...

随机推荐

  1. js发送post请求,实现下载文件

    由于业务需求要下载文件的功能: <!DOCTYPE html> <html> <head> <meta charset="utf-8"&g ...

  2. #Java学习之路——基础阶段(第六篇)

    我的学习阶段是跟着CZBK黑马的双源课程,学习目标以及博客是为了审查自己的学习情况,毕竟看一遍,敲一遍,和自己归纳总结一遍有着很大的区别,在此期间我会参杂Java疯狂讲义(第四版)里面的内容. 前言: ...

  3. [Swift]LeetCode31. 下一个排列 | Next Permutation

    Implement next permutation, which rearranges numbers into the lexicographically next greater permuta ...

  4. [Swift]LeetCode363. 矩形区域不超过 K 的最大数值和 | Max Sum of Rectangle No Larger Than K

    Given a non-empty 2D matrix matrix and an integer k, find the max sum of a rectangle in the matrix s ...

  5. [Swift]LeetCode705. 设计哈希集合 | Design HashSet

    Design a HashSet without using any built-in hash table libraries. To be specific, your design should ...

  6. [Swift]LeetCode738. 单调递增的数字 | Monotone Increasing Digits

    Given a non-negative integer N, find the largest number that is less than or equal to Nwith monotone ...

  7. Docker for windows : 安装Redis

    一.拉取Redis镜像 docker pull hub.c..com/library/redis: 二.创建并运行Redis docker run -d -it --name redis d4f259 ...

  8. 两分钟搞懂UiAutomator、UiAutomator2、Bootstrap的关系

    很多同学经过一段时间的学习之后都明白了Appium的基本原理,但是越学习到后面发现出现的很多陌生名词无法弄清楚其具体作用,今天这篇文章的目的就是为了让大家来弄懂三个高频名词:UiAutomator.U ...

  9. Spring介绍

    Spring介绍 Spring的核心是一个轻量级(Lightweight)的容器(Container),它是实现IoC(Inversion of Control)容器和非入侵性(No intrusiv ...

  10. 如何让div内的多行文本上下左右居中

    1.首先,如果div中的文本特别少,不超过div宽度,那么这种就非常简单了,直接line-height等于height就可以了 <style type="text/css"& ...