You are here

public function SalesforceExampleSubscriber::pullQueryAlter in Salesforce Suite 8.4

Same name and namespace in other branches
  1. 8.3 modules/salesforce_example/src/EventSubscriber/SalesforceExampleSubscriber.php \Drupal\salesforce_example\EventSubscriber\SalesforceExampleSubscriber::pullQueryAlter()
  2. 5.0.x modules/salesforce_example/src/EventSubscriber/SalesforceExampleSubscriber.php \Drupal\salesforce_example\EventSubscriber\SalesforceExampleSubscriber::pullQueryAlter()

SalesforceQueryEvent pull query alter event callback.

Parameters

\Drupal\salesforce_mapping\Event\SalesforceQueryEvent $event: The event.

File

modules/salesforce_example/src/EventSubscriber/SalesforceExampleSubscriber.php, line 101

Class

SalesforceExampleSubscriber
Class SalesforceExampleSubscriber.

Namespace

Drupal\salesforce_example\EventSubscriber

Code

public function pullQueryAlter(SalesforceQueryEvent $event) {
  $mapping = $event
    ->getMapping();
  switch ($mapping
    ->id()) {
    case 'contact':

      // Add attachments to the Contact pull mapping so that we can save
      // profile pics. See also ::pullPresave.
      $query = $event
        ->getQuery();

      // Add a subquery:
      $query->fields[] = "(SELECT Id FROM Attachments WHERE Name = 'example.jpg' LIMIT 1)";

      // Add a field from lookup:
      $query->fields[] = "Account.Name";

      // Add a condition:
      $query
        ->addCondition('Email', "''", '!=');

      // Add a limit:
      $query->limit = 5;
      break;
  }
}