我的代码基本上做我想做的事情,直到我想将响应 ID 写回 Salesforce 的部分。
public class ExpensifyCallout {
//@future(callout=true)
public static void createReport(Id SFReportID, String projectName, Date projectStartDate, Date projectEndDate, String projectReportLocation, String policyID, String employeeEmail){
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('callout:Expensify_API');
request.setHeader('ContentType', 'application/json');
request.setBody('requestJobDescription={"type": "create","credentials": {"partnerUserID": "{!$Credential.Username}" ,"partnerUserSecret": "{!$Credential.Password}"},"inputSettings": {"type": "report","policyID": "'+policyID+'","report": {"title": "'+projectName+'/ '+projectStartDate.format()+' - '+projectEndDate.format()+'/ '+projectReportLocation+'"}, "employeeEmail": "'+employeeEmail+'", "expenses":[]}}');
request.setMethod('POST');
HttpResponse response = http.send(request);
// If the request is successful, parse the JSON response.
if (response.getStatusCode() == 200) {
System.debug(response.getBody());
Map <String, Object> responseJSON = (Map <String, Object>) JSON.deserializeUntyped(response.getBody());
String reportID = string.valueof(responseJSON.get('reportID'));
System.debug('Hello World! ');
System.debug('Hello World! '+ reportID);
/*ExpensifyReport__c[] eRecords = [SELECT Name
FROM ExpensifyReport__c
WHERE Id = :SFReportID];
ExpensifyReport__c e = eRecords[0];
e.expensifyReportID__c = reportID;*/
}
// else handle problem
}
我的 api 响应代码如下:
{"reportID":"54995495","reportName":"My TEST report","responseCode":200}
我想检索 reportID 并将其写回我创建的触发标注的记录。
只有两个带有 Hello World 的语句不会被打印出来。其余的按预期工作。有谁知道为什么会这样?非常感谢。
我注意到一条对我没有多大帮助的错误消息:
Invalid api version:0.0
当我签入设置时,列出的 api 都没有 0.0 版...