【问题标题】:UPDATE records using REST api使用 REST api 更新记录
【发布时间】:2020-02-02 17:38:41
【问题描述】:

我正在处理 PHP 和 Salesforce 集成,我想使用 PHP 更新记录。

我想在单击“跟进”按钮时更新 Salesforce 中的记录。 也可以试试下面的代码。

function update_account($id, $followup, $instance_url, $access_token) {
$url = "$instance_url/services/data/v20.0/sobjects/Contact/$id";


$content = json_encode(array("shivendra__FollowUp__c" => $followup));
echo $content;
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_HTTPHEADER,
        array("Authorization: OAuth $access_token",
            "Content-type: application/json"));
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PATCH");
curl_setopt($curl, CURLOPT_POSTFIELDS, $content);

curl_exec($curl);

$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);

if ( $status != 204 ) {
    die("Error: call to URL $url failed with status $status, curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl));
}
echo "<b>update_contact function</b>";
echo "HTTP status $status updating Contact<br/><br/>";

curl_close($curl);
}

但出现错误:

{"shivendra__FollowUp__c":null}

[{"errorCode":"METHOD_NOT_ALLOWED","message":"HTTP Method 'PATCH' 不允许。允许的是 HEAD,GET,POST"}]

错误:调用 URL https://shivendra-dev-ed.my.salesforce.com/services/data/v20.0/sobjects/Contact/ 失败,状态为 405,curl_error,curl_errno 0

【问题讨论】:

    标签: php rest salesforce integration


    【解决方案1】:

    尝试使用 cURL 的 post 方法,类似于:

    curl_setopt($ch, CURLOPT_POST, 1);

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多