您在此处:
使用 Process Builder 和 Apex 自动将潜在客户添加到节奏
避免销售代表采取额外的步骤。要在创建记录时自动将潜在客户、联系人或个人客户记录添加到节奏,请创建 Apex 类和进程。
所需的 Edition
| 适用于:Lightning Experience |
| 适用于销售参与,它包括在销售业绩、Einstein 1 和 Unlimited Edition 中,另行付费后适用于Professional 和 Enterprise Edition。Sales Engagement 另行付费后适用于 Service 和 Lightning Platform。 |
| 所需用户权限 | |
|---|---|
| 要创建、编辑或查看进程: | 管理流 与 查看所有数据 |
| 定义 Apex 触发器: | 作者 Apex |
| 配置远程设置: | 自定义应用程序 或 修改所有数据 |
| 要将潜在客户添加到节奏: | 销售参与用户 或 包含销售参与用户 |
备注 您不能直接在生产 Salesforce 组织中添加 Apex 类。只有开发人员、试用和 Sandbox 组织支持在“设置”中直接编辑 Apex。要在生产组织中部署 Apex 代码,请先将其添加到 Sandbox 组织,进行测试,然后将其升级到生产组织。
此示例使用 AssignTargetToSalesCadence 操作。您也可以使用 RemoveTargetFromSalesCadence 操作构建流程。
将您的进程设置为仅在创建记录时启动。将您的进程设置为在记录创建和编辑时运行会在节奏中创建重复目标。
-
创建 Apex 类。
- 从“设置”菜单中,选择开发人员控制台。
- 从“文件”菜单中,选择新建 | Apex 类。
- 对于类名称,输入 EnrollTargetIntoSalesCadence。单击确定。
-
在开发人员控制台中,使用以下 Apex 替换您看到的代码。
public class EnrollTargetIntoSalesCadence { @InvocableMethod(label='Enroll Target In Cadence' description='Uses REST Invocable Action to assign a Target to a Cadence') public static void enrollTarget(List<EnrollTargetRequest> targetsToEnroll) { System.debug('*** Targets to enroll *** ' + targetsToEnroll); if (targetsToEnroll != null) { for (EnrollTargetRequest req : targetsToEnroll) { System.debug('*** request *** ' + req); System.debug('\ttarget: ' + req.targetId); System.debug('\tsales cadence: ' + req.salesCadenceName); sendRequest(req.targetId, req.salesCadenceName); } } else { System.debug('*** null targetsToEnroll receieved ***'); } } @future(callout = true) private static void sendRequest(String targetId, String salesCadenceNameOrId) { String sfdcURL = URL.getSalesforceBaseUrl().toExternalForm(); String actionsRestURL = sfdcURL + '/services/data/v45.0/actions'; String assignTargetRESTUrl = actionsRestURL + '/standard/assignTargetToSalesCadence'; HttpRequest httpReq = new HttpRequest(); httpReq.setMethod('POST'); httpReq.setHeader('Authorization', 'OAuth ' + UserInfo.getSessionId()); httpReq.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionId()); httpReq.setEndpoint(assignTargetRESTUrl); httpReq.setHeader('Content-Type', 'application/json'); httpReq.setBody('{"inputs" : [{"salesCadenceNameOrId" : "' + salesCadenceNameOrId + '", "targetId" : "' + targetId + '"}]}'); String response = ''; try { Http http = new Http(); HttpResponse httpResponse = http.send(httpReq); if (httpResponse.getStatusCode() == 200) { response = JSON.serializePretty(JSON.deserializeUntyped(httpResponse.getBody())); } else { System.debug('http response: ' + httpResponse.getBody()); throw new CalloutException(httpResponse.getBody()); } } catch (System.Exception e) { System.debug('ERROR! ' + e); throw e; } System.debug('response: ' + response); } public class EnrollTargetRequest { @InvocableVariable(required=true) public Id targetId; @InvocableVariable(required=true) public String salesCadenceName; } } - 保存 Apex 类。
-
创建进程。
- 从“设置”中,在快速查找框中输入进程构建器。然后单击进程构建器。
- 单击新建。
- 命名进程。
- 在进程开始时菜单,选择A 记录更改。
- 单击保存。
- 在进程构建器中,单击添加对象节点。
- 从右侧窗格的对象菜单中,选择潜在客户、联系人或个人客户。
-
在“开始进程”下,选择仅在创建记录时。
请勿选择何时创建或编辑记录。此设置会使重复目标显示在节奏中。
- 单击保存。
- 在进程构建器中,单击 + 添加条件节点。
-
在右侧窗格中,命名条件。
例如,将其命名为节奏注册触发器。
- 在执行操作的标准下,单击无条件 — 仅执行操作!。
- 单击保存。
- 在您刚添加的条件节点右侧的即时操作节点中,单击 + 添加操作。
-
在右侧窗格中,选择这些设置。
- 操作类型:Apex
- 操作名称:输入操作的名称。
- Apex 类:选择您之前创建的 Apex 类。
- SalesCadenceName:对于值,输入节奏的名称。
- TargetId:对于类型,选择字段引用。对于值,单击字段并搜索 Lead.Id、Contact.Id 或 Account.Id,这取决于您是否要将潜在客户、联系人或个人客户记录添加到节奏。
- 单击保存。
- 单击激活,然后单击确认。
另请参阅:
本文章是否解决您的问题?
请与我们共享您的想法,以便我们进行改进!
