You are here

public function Salesforce::getRecordTypeIdByDeveloperName in Salesforce Suite 7.3

Given a DeveloperName and SObject Name, return the SFID of the corresponding RecordType. DeveloperName doesn't change between Salesforce environments, so it's safer to rely on compared to SFID.

Parameters

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

string $devname : RecordType DeveloperName, e.g. Donation, Membership, etc.

Return value

string SFID The Salesforce ID of the given Record Type, or null.

File

includes/salesforce.inc, line 811
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 getRecordTypeIdByDeveloperName($name, $devname, $reset = FALSE) {
  $cache = cache_get('salesforce_record_types');

  // Force the recreation of the cache when it is older than 5 minutes.
  if ($cache && REQUEST_TIME < $cache->created + 300 && !$reset) {
    return !empty($cache->data[$name][$devname]) ? $cache->data[$name][$devname]['Id'] : NULL;
  }
  $query = new SalesforceSelectQuery('RecordType');
  $query->fields = array(
    'Id',
    'Name',
    'DeveloperName',
    'SobjectType',
  );
  $result = $this
    ->query($query);
  $record_types = array();
  foreach ($result['records'] as $rt) {
    $record_types[$rt['SobjectType']][$rt['DeveloperName']] = $rt;
  }
  cache_set('salesforce_record_types', $record_types, 'cache', CACHE_TEMPORARY);
  return !empty($record_types[$name][$devname]) ? $record_types[$name][$devname]['Id'] : NULL;
}