You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何从Salesforce界面启动UiPath流程及UiPath Robot上的流程?

刚好做过类似的集成,我来一步步给你讲清楚怎么从Salesforce界面触发UiPath流程——核心就是靠Salesforce的REST调用能力对接UiPath Orchestrator的API,毕竟Robot的流程启动都是由Orchestrator统一管控的。

前提准备

在开始之前,你得确保这些前置条件都满足:

  • UiPath Orchestrator已经部署并正常运行,且你的Robot已经成功连接到Orchestrator
  • 要启动的UiPath流程已经发布到Orchestrator对应的环境和文件夹中
  • Salesforce拥有API权限的账号(需要能创建Flow/Apex类、配置远程站点)
  • 已经在Orchestrator中创建了具备流程启动权限的服务账号(后面会详细说)
步骤1:在UiPath Orchestrator中获取关键API信息

首先得拿到Orchestrator那边的必要信息,才能让Salesforce顺利调用:

  1. 获取Orchestrator Base URL:就是你访问Orchestrator的地址,比如https://your-orchestrator-instance.uipath.com
  2. 创建服务账号(Application):
    • 登录Orchestrator,进入Tenant > Applications > 新建Application
    • 选择类型为Machine to Machine,设置名称后保存,就能拿到Client ID和Client Secret
    • 给这个Application分配权限:至少要勾选OR.Execution(执行权限)和OR.Settings(必要的配置权限),如果是特定文件夹的流程,还要在文件夹权限里给这个Application添加Processes > Start权限
  3. 获取流程和Robot的关键信息:
    • 找到要启动的流程,复制它的Process Key(在流程详情页的Release Key字段)
    • 找到目标Robot,复制它的ID(在Robots列表的ID列)
    • 确认流程所在的Environment和Folder名称/ID(如果是多文件夹环境,API调用时可能需要指定)
步骤2:在Salesforce中实现REST调用逻辑

这里分两种方式,适合不同技术能力的场景:

方式一:用Salesforce Flow(无代码/低代码)

如果不想写代码,用Flow就能搞定:

  1. 新建一个Screen Flow(或者Auto-Launched Flow,根据你的触发场景)
  2. 添加一个Get Records元素(如果需要从Salesforce获取数据传递给UiPath流程)
  3. 添加第一个HTTP Callout元素,用来获取Orchestrator的OAuth令牌:
    • 方法:POST
    • 端点:{OrchestratorBaseURL}/identity/connect/token
    • 请求头:Content-Type = application/x-www-form-urlencoded
    • 请求体:grant_type=client_credentials&client_id=你的ClientID&client_secret=你的ClientSecret&scope=OR.Settings OR.Execution
    • 解析响应,提取access_token字段存到变量里
  4. 添加第二个HTTP Callout元素,用来启动UiPath流程:
    • 方法:POST
    • 端点:{OrchestratorBaseURL}/odata/Jobs/UiPath.Server.Configuration.OData.StartJobs
    • 请求头:
      • Content-Type = application/json
      • Authorization = Bearer {刚才获取的access_token}
    • 请求体(JSON格式,按需调整):
      {
        "startInfo": {
          "ReleaseKey": "你的流程ProcessKey",
          "Strategy": "Specific",
          "RobotIds": [你的RobotID],
          "NoOfRobots": 1,
          "Source": "Salesforce",
          "InputArguments": "{\"AccountId\": \"001D000000K0fXOIAZ\"}" // 如果要传参数,这里是JSON字符串
        }
      }
      
  5. 把这个Flow绑定到Salesforce的界面按钮上:比如在对象详情页添加一个自定义按钮,行为选择“Launch a Flow”,选择你创建的Flow即可。

方式二:用Apex代码(更灵活可控)

如果需要更复杂的逻辑或者错误处理,用Apex写个集成类会更合适:

public class UiPathProcessLauncher {
    // 替换成你的Orchestrator信息
    private static final String ORCHESTRATOR_BASE_URL = 'https://your-orchestrator-instance.uipath.com';
    private static final String CLIENT_ID = 'your-client-id-here';
    private static final String CLIENT_SECRET = 'your-client-secret-here';
    private static final String TENANT_NAME = 'your-tenant-name';

    // 获取Orchestrator的OAuth访问令牌
    public static String getOrchestratorAccessToken() {
        HttpRequest tokenReq = new HttpRequest();
        tokenReq.setMethod('POST');
        tokenReq.setEndpoint(ORCHESTRATOR_BASE_URL + '/identity/connect/token');
        tokenReq.setHeader('Content-Type', 'application/x-www-form-urlencoded');
        
        String tokenBody = String.format(
            'grant_type=client_credentials&client_id={0}&client_secret={1}&scope=OR.Settings OR.Execution',
            new List<String>{CLIENT_ID, CLIENT_SECRET}
        );
        tokenReq.setBody(tokenBody);

        Http http = new Http();
        HttpResponse tokenRes = http.send(tokenReq);
        
        if (tokenRes.getStatusCode() != 200) {
            throw new CustomException('获取Orchestrator令牌失败: ' + tokenRes.getBody());
        }

        Map<String, Object> tokenRespMap = (Map<String, Object>)JSON.deserializeUntyped(tokenRes.getBody());
        return (String)tokenRespMap.get('access_token');
    }

    // 启动指定的UiPath流程
    public static void launchProcess(String processKey, Integer robotId, String inputArgs) {
        String accessToken = getOrchestratorAccessToken();
        
        HttpRequest launchReq = new HttpRequest();
        launchReq.setMethod('POST');
        launchReq.setEndpoint(ORCHESTRATOR_BASE_URL + '/odata/Jobs/UiPath.Server.Configuration.OData.StartJobs');
        launchReq.setHeader('Content-Type', 'application/json');
        launchReq.setHeader('Authorization', 'Bearer ' + accessToken);

        // 构建启动请求的JSON体
        Map<String, Object> startInfo = new Map<String, Object>{
            'ReleaseKey' => processKey,
            'Strategy' => 'Specific',
            'RobotIds' => new List<Integer>{robotId},
            'NoOfRobots' => 1,
            'Source' => 'Salesforce Integration',
            'InputArguments' => inputArgs
        };
        Map<String, Object> requestBody = new Map<String, Object>{'startInfo' => startInfo};
        
        launchReq.setBody(JSON.serialize(requestBody));
        HttpResponse launchRes = http.send(launchReq);

        if (launchRes.getStatusCode() != 201) {
            throw new CustomException('启动UiPath流程失败: ' + launchRes.getBody());
        }
    }

    // 自定义异常类,用于错误捕获
    public class CustomException extends Exception {}
}

写完类之后,你可以:

  • 把这个方法绑定到自定义按钮上:在对象布局里添加“Execute Apex”类型的按钮,选择UiPathProcessLauncher.launchProcess方法,并传递对应的参数(比如流程Key、Robot ID、输入参数)
  • 或者在其他Apex逻辑中直接调用这个方法,实现更复杂的触发场景
步骤3:配置Salesforce远程站点设置

Salesforce默认禁止调用外部API,所以必须把Orchestrator的URL添加到远程站点:

  1. 进入Salesforce Setup > Security > Remote Site Settings
  2. 点击“New Remote Site”,输入站点名称,把Orchestrator的Base URL填进去(比如https://your-orchestrator-instance.uipath.com)
  3. 勾选“Active”,保存即可。
步骤4:测试验证

现在可以在Salesforce界面点击你创建的按钮,然后:

  1. 去UiPath Orchestrator的Jobs页面,看是否有新的作业被创建
  2. 查看对应的Robot,确认流程是否开始执行
  3. 如果有错误,检查Salesforce的Flow/Apex日志,或者Orchestrator的日志,排查问题
一些注意事项
  • API版本兼容:UiPath Orchestrator的API会定期更新,建议使用官方文档推荐的稳定版本,避免接口变更导致调用失败
  • 权限问题:Orchestrator的服务账号必须有对应文件夹的流程启动权限,Robot必须处于在线状态
  • 参数传递:如果要把Salesforce的数据传给UiPath流程,InputArguments必须是合法的JSON字符串,注意转义特殊字符
  • 错误处理:在Flow或Apex中添加错误捕获逻辑,给用户友好的提示(比如令牌过期、流程启动失败等)

内容的提问来源于stack exchange,提问作者Cristian Negulescu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.07 08:32:36