You are here

function salesforce_api_connect in Salesforce Suite 5.2

Same name and namespace in other branches
  1. 6.2 salesforce_api/salesforce_api.module \salesforce_api_connect()
  2. 7 salesforce_api/salesforce_api.module \salesforce_api_connect()
  3. 7.2 salesforce_api/salesforce_api.module \salesforce_api_connect()

Creates an object used for communicating with the Salesforce server and performs a login to verify the API credentials.

Parameters

$reconnect: By default, subsequent calls to this function will return the same, already connected Salesforce object as preceding calls. Setting this variable to TRUE will cause a new connection to be established instead.

Return value

The DrupalSalesforce object used to communicate with the Salesforce server if successful or FALSE if a connection could not be established.

7 calls to salesforce_api_connect()
salesforce_api_demo in salesforce_api/salesforce_api.module
Demonstrates some of the API functionality through the Salesforce class and fieldmap functionality.
sf_node_export in sf_node/sf_node.module
Exports a node to Salesforce using the specified fieldmap and stores the ID of the Salesforce object for the node.
sf_node_import in sf_node/sf_node.module
Imports data from Salesforce into a node.
sf_node_salesforce_form in sf_node/sf_node.module
sf_user_export in sf_user/sf_user.module
Exports a user to Salesforce using the specified fieldmap and stores the ID of the Salesforce object for the user.

... See full list

File

salesforce_api/salesforce_api.module, line 203
Defines an API that enables modules to interact with the Salesforce server.

Code

function salesforce_api_connect($reconnect = FALSE) {
  static $sf = FALSE;

  // Return the previously connected object.
  if ($sf && !$reconnect) {
    return $sf;
  }

  // Load up the API credentials.
  $username = variable_get('salesforce_api_username', '');
  $password = variable_get('salesforce_api_password', '');
  $token = variable_get('salesforce_api_token', '');

  // Fail early if we didn't receive an API username, password, or token.
  if (empty($username) || empty($password) || empty($token)) {
    watchdog('salesforce', 'Connection to Salesforce failed because API credentials have not been set.', array(), WATCHDOG_ERROR);
    return FALSE;
  }

  // Include the file that defines the class.
  require_once drupal_get_path('module', 'salesforce_api') . '/salesforce.class.inc';

  // Create a new Salesforce object with the API credentials.
  $sf = new DrupalSalesforce($username, $password, $token);

  // Attempt a login, and...
  if ($sf
    ->login()) {

    // Return the object if a connection and login were successful.
    return $sf;
  }
  else {

    // Or return FALSE to indicate the failure.
    $sf = FALSE;
    return FALSE;
  }
}