You are here

protected function SalesforceMappingFormBase::ensureConnection in Salesforce Suite 8.3

Test the Salesforce connection by issuing the given api call.

Parameters

string $method: Which method to test on the Salesforce client. Defaults to "objects".

mixed $arg: An argument to send to the test method. Defaults to empty array.

Return value

bool TRUE if Salesforce endpoint (or cache) responded correctly.

2 calls to SalesforceMappingFormBase::ensureConnection()
SalesforceMappingFieldsForm::buildForm in modules/salesforce_mapping/src/Form/SalesforceMappingFieldsForm.php
Form constructor.
SalesforceMappingFormCrudBase::buildForm in modules/salesforce_mapping/src/Form/SalesforceMappingFormCrudBase.php
Form constructor.

File

modules/salesforce_mapping/src/Form/SalesforceMappingFormBase.php, line 84

Class

SalesforceMappingFormBase
Salesforce Mapping Form base.

Namespace

Drupal\salesforce_mapping\Form

Code

protected function ensureConnection($method = 'objects', $arg = []) {
  try {
    $this->client
      ->{$method}($arg);
  } catch (\Exception $e) {
    $href = new Url('salesforce.admin_config_salesforce');
    $this
      ->messenger()
      ->addError($this
      ->t('Error when connecting to Salesforce. Please <a href="@href">check your credentials</a> and try again: %message', [
      '@href' => $href
        ->toString(),
      '%message' => $e
        ->getMessage() ?: get_class($e),
    ]), 'error');
    return FALSE;
  }
  return TRUE;
}