Skip to content
Snippets Groups Projects
Commit 29b257a8 authored by Gabriel Carleton-Barnes's avatar Gabriel Carleton-Barnes
Browse files

Allow configurable record type filtering based on record type ID on pulls. #14260720

parent b104017e
No related branches found
No related tags found
No related merge requests found
......@@ -49,6 +49,9 @@ salesforce_mapping.salesforce_mapping.*:
pull_where_clause:
type: string
label: 'Pull query SOQL "WHERE" clause'
pull_record_type_filter:
type: mapping
label: 'Pull query record type filter'
sync_triggers:
type: mapping
label: 'Sync triggers'
......
......@@ -40,6 +40,7 @@ use Drupal\salesforce_mapping\MappingConstants;
* "pull_standalone",
* "pull_trigger_date",
* "pull_where_clause",
* "pull_record_type_filter",
* "sync_triggers",
* "salesforce_object_type",
* "drupal_entity_type",
......@@ -140,6 +141,13 @@ class SalesforceMapping extends ConfigEntityBase implements SalesforceMappingInt
*/
protected $pull_where_clause = '';
/**
* Pull query record type filter.
*
* @var array
*/
protected $pull_record_type_filter = [];
/**
* The drupal entity type to which this mapping points.
*
......@@ -686,6 +694,18 @@ class SalesforceMapping extends ConfigEntityBase implements SalesforceMappingInt
if (!empty($this->pull_where_clause)) {
$soql->conditions[] = [$this->pull_where_clause];
}
if (!empty($this->pull_record_type_filter)) {
$record_types = [];
foreach ($this->pull_record_type_filter as $enabled) {
if ($enabled) {
$record_types[] = $enabled;
}
}
if (!empty($record_types)) {
$record_types_list = implode("', '", $record_types);
$soql->conditions[] = ["RecordType.Id IN ('" . $record_types_list . "')"];
}
}
$soql->order[$this->getPullTriggerDate()] = 'ASC';
return $soql;
}
......
......@@ -25,6 +25,7 @@ push_standalone: false
pull_standalone: false
pull_trigger_date: LastModifiedDate
pull_where_clause: ''
pull_record_type_filter: []
sync_triggers:
push_create: true
push_update: true
......
......@@ -116,12 +116,16 @@ abstract class SalesforceMappingFormCrudBase extends SalesforceMappingFormBase {
];
$salesforce_object_type = '';
$salesforce_object = NULL;
if (!empty($form_state->getValues()) && !empty($form_state->getValue('salesforce_object_type'))) {
$salesforce_object_type = $form_state->getValue('salesforce_object_type');
}
elseif ($mapping->salesforce_object_type) {
$salesforce_object_type = $mapping->salesforce_object_type;
}
if (!empty($salesforce_object_type)) {
$salesforce_object = $this->client->objectDescribe($salesforce_object_type);
}
$form['salesforce_object']['salesforce_object_type'] = [
'#title' => $this->t('Salesforce Object'),
'#id' => 'edit-salesforce-object-type',
......@@ -218,11 +222,18 @@ abstract class SalesforceMappingFormCrudBase extends SalesforceMappingFormBase {
'#default_value' => $mapping->pull_where_clause,
];
$form['pull']['pull_where_clause'] = [
'#title' => $this->t('Pull query SOQL "Where" clause'),
'#type' => 'textarea',
'#description' => $this->t('Add a "where" SOQL condition clause to limit records pulled from Salesforce. e.g. Email != \'\' AND RecordType.DevelopName = \'ExampleRecordType\''),
'#default_value' => $mapping->pull_where_clause,
$record_type_options = [];
if ($salesforce_object && !empty($salesforce_object->recordTypeInfos)) {
foreach ($salesforce_object->recordTypeInfos as $record_type_info) {
$record_type_options[$record_type_info['recordTypeId']] = $record_type_info['name'];
}
}
$form['pull']['pull_record_type_filter'] = [
'#title' => $this->t('Record Types to Request'),
'#type' => 'checkboxes',
'#options' => $record_type_options,
'#description' => $this->t('Restrict the record types to pull from Salesforce. If you set no values, all types will be requested.'),
'#default_value' => $mapping->pull_record_type_filter ?: [],
];
$form['pull']['pull_frequency'] = [
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment