开发者

CF8 and Salesforce REST API - updating records

I'm trying to do integration with Salesforce using their REST API and CF8. I got the OAuth bit working, getting data etc but now I'm trying to update some records in Contact table.

First I tought about doing it the "proper" way as their docs say -

Update a record using HTTP PATCH.

But CFHTTP doesn't support PATCH method.

So then I tried running a SOQL query开发者_Python百科:

UPDATE Contact SET MailingStreet = 'Blah Blah' WHERE Id = '003A000000Zp4ObIAJ'

but here I'm getting

{"message":"unexpected token: UPDATE","errorCode":"MALFORMED_QUERY"}

Does anyone have an idea how to do it?


You can create your own PATCH method if your client supports it, but there is an easier way. From the Force.com REST API Developer's Guide:

If you use an HTTP library that doesn't allow overriding or setting an arbitrary HTTP method name, you can send a POST request and provide an override to the HTTP method via the query string parameter _HttpMethod. In the PATCH example, you can replace the PostMethod line with one that doesn't use override:

PostMethod m = new PostMethod(url + "?_HttpMethod=PATCH");


In CF9 CFScript, using the method that Paddyslacker already suggested for adding _HttpMethod=PATCH to the URL:

private boolean function patchObject(required string sfid, required string type, required struct obj) {
    local.url = variables.salesforceInstance & '/services/data/v' & variables.apiVersion &'/sobjects/' & arguments.type & '/' & arguments.sfid &'?_HttpMethod=PATCH';
    local.http = new Http(url=local.url,method='post');
    //... convert obj to a json string, add to local.http ...
    local.httpSendResult = local.http.send().getPrefix();
}

We have a CF9 CFC that we wrote that wraps most of the REST API that we will be open sourcing soon. I'll come back and link to it when we do.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜