Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in Salesforce by (11.9k points)

Hi this is a long shot but I'm attempting to insert data into a sales-force Object through an API call from PHP(Codeigniter framework). I am using CURL protocol and the record is not being inserted but I receive no error message either.

All my parameters for connection are correct and I get retrieve records/update records successfully but I cannot insert.

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));

}

The function call:

$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);

this is what $results array contains:

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)
  }
}

1 Answer

0 votes
by (32.1k points)
edited by
It seems like you are making a GET request but you actually need to use POST request in order to create a new record.

Related questions

0 votes
1 answer
asked Jul 17, 2019 in Salesforce by Kartik12234 (11.9k points)
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...