public function SalesforceMapping::getPullQuery in Salesforce Suite 8.3
Same name and namespace in other branches
- 8.4 modules/salesforce_mapping/src/Entity/SalesforceMapping.php \Drupal\salesforce_mapping\Entity\SalesforceMapping::getPullQuery()
- 5.0.x modules/salesforce_mapping/src/Entity/SalesforceMapping.php \Drupal\salesforce_mapping\Entity\SalesforceMapping::getPullQuery()
Generate a select query to pull records from Salesforce for this mapping.
Parameters
array $mapped_fields: Fetch only these fields, if given, otherwise fetch all mapped fields.
int $start: Timestamp of starting window from which to pull records. If omitted, use ::getLastPullTime()
int $stop: Timestamp of ending window from which to pull records. If omitted, use "now".
Return value
\Drupal\salesforce\SelectQuery The pull query.
Overrides SalesforceMappingInterface::getPullQuery
File
- modules/
salesforce_mapping/ src/ Entity/ SalesforceMapping.php, line 597
Class
- SalesforceMapping
- Defines a Salesforce Mapping configuration entity class.
Namespace
Drupal\salesforce_mapping\EntityCode
public function getPullQuery(array $mapped_fields = [], $start = 0, $stop = 0) {
if (!$this
->doesPull()) {
throw new Exception('Mapping does not pull.');
}
$object_type = $this
->getSalesforceObjectType();
$soql = new SelectQuery($object_type);
// Convert field mappings to SOQL.
if (empty($mapped_fields)) {
$mapped_fields = $this
->getPullFieldsArray();
}
$soql->fields = $mapped_fields;
$soql->fields[] = 'Id';
$soql->fields[] = $this
->getPullTriggerDate();
$start = $start > 0 ? $start : $this
->getLastPullTime();
// If no lastupdate and no start window provided, get all records.
if ($start) {
$start = gmdate('Y-m-d\\TH:i:s\\Z', $start);
$soql
->addCondition($this
->getPullTriggerDate(), $start, '>');
}
if ($stop) {
$stop = gmdate('Y-m-d\\TH:i:s\\Z', $stop);
$soql
->addCondition($this
->getPullTriggerDate(), $stop, '<');
}
if (!empty($this->pull_where_clause)) {
$soql->conditions[] = [
$this->pull_where_clause,
];
}
$soql->order[$this
->getPullTriggerDate()] = 'ASC';
return $soql;
}