You are here

function DrupalSalesforce::login in Salesforce Suite 7

Same name and namespace in other branches
  1. 5.2 salesforce_api/ \DrupalSalesforce::login()

Establishes a connection and logs in to the Salesforce server.

Return value

TRUE or FALSE indicating the success of the login.


salesforce_api/, line 51
Defines the class used for communicating with the Salesforce server.




function login() {

  // Default to the WSDL downloaded from the user account if available.
  $wsdl = SALESFORCE_DIR_WSDL . '/enterprise.wsdl.xml';

  // Otherwise fall back to the one included with the Toolkit.
  if (!file_exists($wsdl)) {
    $wsdl = SALESFORCE_DIR_SOAPCLIENT . '/enterprise.wsdl.xml';

  // Connect to the server and login, logging any failures to the watchdog.
  try {

    // Connect to the server.

    // Attempt a login with the credentials entered by the user.
    $this->login = $this->client
      ->login($this->username, $this->password . $this->token);

    // Log the login occurence.
      ->watchdog(SALESFORCE_LOG_ALL, '@user (@email) logged into Salesforce.', array(
      '@user' => $this->login->userInfo->userFullName,
      '@email' => $this->login->userInfo->userEmail,
  } catch (Exception $e) {

    // Log the error message.
      ->watchdog(SALESFORCE_LOG_SOME, 'Could not login to Salesforce: %message. <pre>!debug</pre>', array(
      '%message' => $e->faultstring,
      '!debug' => check_plain($this->client

    // Indicate the failed login.
    return FALSE;

  // Indicate the successful login.
  return TRUE;