You are here

public function Salesforce::objectUpsert in Salesforce Suite 7.3

Create new records or update existing records.

The new records or updated records are based on the value of the specified field. If the value is not unique, REST API returns a 300 response with the list of matching records.

Parameters

string $name: Object type name, E.g., Contact, Account.

string $key: The field to check if this record should be created or updated.

string $value: The value for this record of the field specified for $key.

array $params: Values of the fields to set for the object.

Return value

array success: "id" : "00190000001pPvHAAU", "errors" : [ ], "success" : true error: "message" : "The requested resource does not exist" "errorCode" : "NOT_FOUND"

File

includes/salesforce.inc, line 646
Objects, properties, and methods to communicate with the Salesforce REST API

Class

Salesforce
Ability to authorize and communicate with the Salesforce REST API.

Code

public function objectUpsert($name, $key, $value, $params) {

  // If key is set, remove from $params to avoid UPSERT errors.
  if (isset($params[$key])) {
    unset($params[$key]);
  }
  $data = $this
    ->apiCall("sobjects/{$name}/{$key}/{$value}", $params, 'PATCH');
  if ($this->response->code == 300) {
    $data['message'] = t('The value provided is not unique.');
  }
  return $data;
}