diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index 566adf24fe7b..f0eaf258842d 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -4768,8 +4768,13 @@ public static function isCustomDateField($fieldName) { if (($customFieldID = CRM_Core_BAO_CustomField::getKeyID($fieldName)) == FALSE) { return FALSE; } - if ('Date' == civicrm_api3('CustomField', 'getvalue', ['id' => $customFieldID, 'return' => 'data_type'])) { - return TRUE; + try { + $customFieldDataType = civicrm_api3('CustomField', 'getvalue', ['id' => $customFieldID, 'return' => 'data_type']); + if ('Date' == $customFieldDataType) { + return TRUE; + } + } + catch (CiviCRM_API3_Exception $e) { } return FALSE; } diff --git a/tests/phpunit/CRM/Contact/BAO/SavedSearchTest.php b/tests/phpunit/CRM/Contact/BAO/SavedSearchTest.php index 3f8d38756cd1..e2dc8229b21a 100644 --- a/tests/phpunit/CRM/Contact/BAO/SavedSearchTest.php +++ b/tests/phpunit/CRM/Contact/BAO/SavedSearchTest.php @@ -80,6 +80,10 @@ public function testDefaultValues() { $defaults = $sg->setDefaultValues(); $this->checkArrayEquals($defaults, $formValues); + $this->callAPISuccess('CustomField', 'delete', ['id' => $this->ids['CustomField']['int']]); + unset($this->ids['CustomField']['int']); + $defaults = $sg->setDefaultValues(); + $this->checkArrayEquals($defaults, $formValues); } /**