【发布时间】:2020-05-20 21:01:35
【问题描述】:
概览:
我们有第三方在给定端点托管文本值。使用对 url 的“获取”请求,我们还传递一个键和参数返回一个字符串值(十进制数字和一个空格)。 我创建了一些顶点代码,包括@InvocableMethod,所以我可以从我传入 URL 的流中获取所有顶点,然后将文本返回到流中。然后我继续更新记录。 这是方法, 还有一个类 FR_Amount_Variables ,存储 URL 和字符串 @InvocableVariable 值。
public class FR_Amount_Sync {
@InvocableMethod(label='FR Amount Raised Get')
public static List<FR_Amount_Variables>getFRamount (List<FR_Amount_Variables> inputURL) {
FR_Amount_Variables amtvar = new FR_Amount_Variables();
List<FR_Amount_Variables> getFRamount = new List<FR_Amount_Variables>();
string endpoint = inputURL[0].URL;
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint(endpoint);
request.setMethod('GET');
HttpResponse response = http.send(request);
string Amounts= response.getBody();
Amounts= Amounts.replaceAll( '\\s+', '');
if(String.isEmpty(Amounts)){
Boolean isEmpty = true;
Amounts = '0.00';
}
decimal amountss = decimal.valueOf(Amounts);
amtvar.amount = amountss;
getFRamount.add(amtvar);
return getFRamount;
}
}
流程的图像可以在下面看到 Update Flow
问题:
当我在调试模式下运行流程时,设置 3 个输入变量并运行,流程执行顶点并正确更新指定记录。 同样,如果我预设了流程的输入变量(添加默认值),并且只是运行流程,那么顶点和记录更新会成功,记录会使用来自第 3 方的正确值进行更新。 问题是当我尝试通过 Process Builder 或 Mass Action Scheduler 自动运行流程时,我收到系统异常错误。 发生 Apex 错误:
System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out
和
An Apex error occurred: System.CalloutException: Callout loop not allowed
分别。
我想知道是否有任何方法可以触发不会触发错误的流程。否则有没有办法我可以进行 httprequest 'get' 标注,然后用收到的记录更新记录。
【问题讨论】:
标签: get httprequest apex flow dml