diff --git a/CRM/Case/BAO/Case.php b/CRM/Case/BAO/Case.php index 14946c4c1334..78943a5254a1 100644 --- a/CRM/Case/BAO/Case.php +++ b/CRM/Case/BAO/Case.php @@ -1235,7 +1235,7 @@ public static function getRelatedContacts($caseID, $includeDetails = TRUE) { LEFT JOIN civicrm_email ce ON ce.contact_id = cc.id AND ce.is_primary= 1 - WHERE cr.case_id = %1'; + WHERE cr.case_id = %1 AND cr.is_active AND cc.is_deleted <> 1'; $params = array(1 => array($caseID, 'Integer')); $dao = CRM_Core_DAO::executeQuery($query, $params); diff --git a/api/v3/Case.php b/api/v3/Case.php index 849e32228de3..ddf3aead95c2 100644 --- a/api/v3/Case.php +++ b/api/v3/Case.php @@ -269,7 +269,7 @@ function civicrm_api3_case_get($params, $sql = NULL) { // Add necessary joins to the first case client if ($contactSort) { $sql->join('ccc', 'LEFT JOIN (SELECT * FROM civicrm_case_contact WHERE id IN (SELECT MIN(id) FROM civicrm_case_contact GROUP BY case_id)) AS ccc ON ccc.case_id = a.id'); - $sql->join('case_contact', 'LEFT JOIN civicrm_contact AS case_contact ON ccc.contact_id = case_contact.id'); + $sql->join('case_contact', 'LEFT JOIN civicrm_contact AS case_contact ON ccc.contact_id = case_contact.id AND case_contact.is_deleted <> 1'); } }