【问题标题】:JSON insert records into SalesforceJSON 将记录插入 Salesforce
【发布时间】:2013-06-05 07:57:34
【问题描述】:

您好,这是一个长镜头,但我正在尝试通过来自 PHP(Codeigniter 框架)的 API 调用将数据插入到销售人员对象中。我正在使用 CURL 协议并且没有插入记录,但我也没有收到错误消息。

我所有的连接参数都是正确的,我成功地检索记录/更新记录,但我无法插入。

public function insert_record($object_name, $field_list=FALSE) {

    $request = trim($this->instance_url).
    '/services/data/'.$this->api_version.'/sobjects/'.trim($object_name).'/';
    return $this->execute_request($request, FALSE , json_encode($field_list));
}

函数调用:

$record_to_insert = array("Name__c" => 
"Ricky Hernadez", "Status__c" => "Single", 
"Description__c" => "This is a test");


$this->data['results'] =$results = $this->salesforce->insert_record("Online_Participant__c", $record_to_insert);

这是 $results 数组包含的内容:

object(stdClass)#24 (2) {
  ["recentItems"]=>
  array(1) {
    [0]=>
    object(stdClass)#25 (3) {
      ["attributes"]=>
      object(stdClass)#26 (2) {
        ["type"]=>
        string(21) "Online_Participant__c"
        ["url"]=>
        string(70) "/services/data/v22.0/sobjects/Online_Participant__c/a0bi00000027HGbAAM"
      }
      ["Id"]=>
      string(18) "a0bi00000027HGbAAM"
      ["Name"]=>
      string(6) "OP0004"
    }
  }
  ["objectDescribe"]=>
  object(stdClass)#27 (21) {
    ["name"]=>
    string(21) "Online_Participant__c"
    ["label"]=>
    string(18) "Online Participant"
    ["keyPrefix"]=>
    string(3) "a0b"
    ["labelPlural"]=>
    string(19) "Online Participants"
    ["custom"]=>
    bool(true)
    ["layoutable"]=>
    bool(true)
    ["activateable"]=>
    bool(false)
    ["urls"]=>
    object(stdClass)#28 (3) {
      ["sobject"]=>
      string(51) "/services/data/v22.0/sobjects/Online_Participant__c"
      ["describe"]=>
      string(60) "/services/data/v22.0/sobjects/Online_Participant__c/describe"
      ["rowTemplate"]=>
      string(56) "/services/data/v22.0/sobjects/Online_Participant__c/{ID}"
    }
    ["searchable"]=>
    bool(true)
    ["deprecatedAndHidden"]=>
    bool(false)
    ["createable"]=>
    bool(true)
    ["updateable"]=>
    bool(true)
    ["deletable"]=>
    bool(true)
    ["customSetting"]=>
    bool(false)
    ["feedEnabled"]=>
    bool(false)
    ["mergeable"]=>
    bool(false)
    ["queryable"]=>
    bool(true)
    ["replicateable"]=>
    bool(true)
    ["retrieveable"]=>
    bool(true)
    ["undeletable"]=>
    bool(true)
    ["triggerable"]=>
    bool(true)
  }
}

【问题讨论】:

  • 你确定失败了?您的回复似乎包含生成的 id (a0bi00000027HGbAAM)、名称和 URL,您可以使用它们通过 REST (/services/data/v22.0/sobjects/Online_Participant__c/a0bi00000027HGbAAM) 获取数据...转到 https://instance.salesforce.com/a0bi00000027HGbAAM?另外 - 您使用哪个 HTTP 动词?应该是 POST 用于插入,PATCH 用于更新,GET 用于检索等。

标签: php json codeigniter rest salesforce


【解决方案1】:

您似乎正在发出 GET 请求,您需要使用 POST 来创建新记录。

【讨论】:

    【解决方案2】:

    我强烈建议您使用 Force.com PHP Toolkit,因为您将避免此类问题。

    您可以从这里下载它: http://wiki.developerforce.com/page/Force.com_Toolkit_for_PHP

    示例代码: http://wiki.developerforce.com/page/PHP_Toolkit_20.0_Samples

    【讨论】:

    • Force.com PHP 工具包已过时。我无法将数据更新到 Salesforce。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多