You are here

public static function SObject::createIfValid in Salesforce Suite 5.0.x

Same name and namespace in other branches
  1. 8.4 src/SObject.php \Drupal\salesforce\SObject::createIfValid()

Given SObject data, instantiate a new SObject if data is valid.

Parameters

array $data: SOBject data.

Return value

\Drupal\salesforce\SObject|false SObject, or FALSE if data is not valid.

1 call to SObject::createIfValid()
SelectQueryResult::__construct in src/SelectQueryResult.php
SelectQueryResult constructor.

File

src/SObject.php, line 73

Class

SObject
Class SObject.

Namespace

Drupal\salesforce

Code

public static function createIfValid(array $data = []) {
  if (!isset($data['id']) && !isset($data['Id'])) {
    return FALSE;
  }
  if (isset($data['id'])) {
    $data['Id'] = $data['id'];
  }
  if (!SFID::isValid($data['Id'])) {
    return FALSE;
  }
  if (empty($data['attributes']) || !isset($data['attributes']['type'])) {
    return FALSE;
  }
  return new static($data);
}