从Google Apps脚本更新Salesforce记录

时间:2014-03-21 15:44:08

标签: google-apps-script salesforce

我正在尝试从Google Apps脚本更新自定义salesforce对象中的单个字段。该字段是一个复选框。这是应用程序脚本代码

     try {
       var payload = Utilities.jsonStringify(
          {"update_GApps_Directory__c": 0
          }
        );
        var contentType = "application/json; charset=utf-8";
        var feedUrl = instanceUrl + "/services/data/v23.0/sobjects/GApps_User_Directory__c/" + userId
        var response = UrlFetchApp.fetch(feedUrl, {method: "PATCH",headers: {"Authorization": "OAuth " + accessToken}, payload: payload, contentType: contentType});
        var postResult = Utilities.jsonParse(response.getContentText());
    } catch (err) {
        Logger.log("POST ERROR: " + err);
    }

生成的请求,经过修改以隐藏一些内容;

C / jim.xxxon @ nexxxxxxxginc.com,%20%7Bheaders =%7BAuthorization = OAuth的%2000D80xxxxxxxxxxxxBAJZRUEIeMrwFymv5_MAQfwerIlDuSd8oAFYuKyxxxxxxxxxrnnIowtwHozI%7D,%20payload =%7B%22update_GApps_Directory__c%22:0%7D,%20method = PATCH,%20contentType =应用/json;%20charset=utf-8%7D">https://na8.salesforce.com/services/data/v23.0/sobjects/GApps_User_Directory_c/jim.xxxon@nexxxxxxxginc.com,%20 %7Bheaders =%7BAuthorization = OAuth的%2000D80xxxxxxxxxxxxBAJZRUEIeMrwFymv5 _MAQfwerIlDuSd8oAFYuKyxxxxxxxxxrnnIowtwHozI%7D,%20payload =%7B%22update_GApps_Directory__c%22:0%7D,%20method = PATCH,%20contentType =应用/ JSON;%20charset = UTF-8% 7D

和错误;

异常:属性提供无效值:方法

我假设它意味着它不喜欢Patch作为方法。对象GApps_User_Directory__c具有唯一的外部ID,这是一个电子邮件地址,并且该记录确实存在。我究竟做错了什么?在此先感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

我在这里找到了答案,https://salesforce.stackexchange.com/questions/13294/patch-request-using-apex-httprequest我必须使用post方法并通过在其末尾添加“?_HttpMethod = PATCH”来“覆盖”方法来修补Feed网址。