You are here

public function RestClient::getObjectTypeName in Salesforce Suite 8.3

Same name and namespace in other branches
  1. 8.4 src/Rest/RestClient.php \Drupal\salesforce\Rest\RestClient::getObjectTypeName()
  2. 5.0.x src/Rest/RestClient.php \Drupal\salesforce\Rest\RestClient::getObjectTypeName()

Utility function to determine object type for given SFID.

Parameters

\Drupal\salesforce\SFID $id: The SFID.

Return value

string The object type name.

Throws

\Exception If SFID doesn't match any object type.

Overrides RestClientInterface::getObjectTypeName

File

src/Rest/RestClient.php, line 877

Class

RestClient
Objects, properties, and methods to communicate with the Salesforce REST API.

Namespace

Drupal\salesforce\Rest

Code

public function getObjectTypeName(SFID $id) {
  $prefix = substr((string) $id, 0, 3);
  $describe = $this
    ->objects();
  foreach ($describe as $object) {
    if ($prefix == $object['keyPrefix']) {
      return $object['name'];
    }
  }
  throw new \Exception('No matching object type');
}