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. 算法与数据结构(八) AOV网的关键路径(Swift版)

    上篇博客我们介绍了AOV网的拓扑序列,请参考<数据结构(七) AOV网的拓扑排序(Swift面向对象版)>.拓扑序列中包括项目的每个结点,沿着拓扑序列将项目进行下去是肯定可以将项目完成的, ...

  2. [Swift]LeetCode30. 与所有单词相关联的字串 | Substring with Concatenation of All Words

    You are given a string, s, and a list of words, words, that are all of the same length. Find all sta ...

  3. [Swift]LeetCode258. 各位相加 | Add Digits

    Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. ...

  4. [Swift]LeetCode409. 最长回文串 | Longest Palindrome

    Given a string which consists of lowercase or uppercase letters, find the length of the longest pali ...

  5. [Swift]LeetCode847. 访问所有节点的最短路径 | Shortest Path Visiting All Nodes

    An undirected, connected graph of N nodes (labeled 0, 1, 2, ..., N-1) is given as graph. graph.lengt ...

  6. kubernetes---kubectl 管理集群资源

    由于我现在的集群是把虚拟机的master文件直接拷贝过来的,所以之前的node节点是不存在的,只有k8s-ubuntu-1是新加入的,所以我要把上面之前创建的资源删除 删除deployment--&g ...

  7. MySQL优化配置之query_cache_size

    原理MySQL查询缓存保存查询返回的完整结果.当查询命中该缓存,会立刻返回结果,跳过了解析,优化和执行阶段.  查询缓存会跟踪查询中涉及的每个表,如果这写表发生变化,那么和这个表相关的所有缓存都将失效 ...

  8. 基于 dubbo 的分布式架构

    前言 现在越来越多的互联网公司还是将自己公司的项目进行服务化,这确实是今后项目开发的一个趋势,就这个点再凭借之前的 SSM 项目来让第一次接触的同学能快速上手. 浅谈分布式架构 分布式架构单看这个名字 ...

  9. Django知识点

    一.Django        pip3 install django            C:\Python35\Scripts        # 创建Django工程    django-adm ...

  10. linux-centerOs6.8安装nginx与配置

    一:安装nginx 1.安装gcc(命令:yum install gcc)备注:可以输入gcc -v查询版本信息,查看是否自带安装 2.安装pcre(命令:yum install pcre-devel ...