diff --git a/CRM/Activity/BAO/Activity.php b/CRM/Activity/BAO/Activity.php
index 787a1c955d08..b728e341e528 100644
--- a/CRM/Activity/BAO/Activity.php
+++ b/CRM/Activity/BAO/Activity.php
@@ -596,13 +596,6 @@ public static function create(&$params) {
 
     CRM_Contact_BAO_GroupContactCache::opportunisticCacheFlush();
 
-    if (!empty($params['id'])) {
-      CRM_Utils_Hook::post('edit', 'Activity', $activity->id, $activity);
-    }
-    else {
-      CRM_Utils_Hook::post('create', 'Activity', $activity->id, $activity);
-    }
-
     // if the subject contains a ‘[case #…]’ string, file that activity on the related case (CRM-5916)
     $matches = array();
     $subjectToMatch = CRM_Utils_Array::value('subject', $params);
@@ -626,6 +619,12 @@ public static function create(&$params) {
         self::logActivityAction($activity, "Case details for {$matches[1]} not found while recording an activity on case.");
       }
     }
+    if (!empty($params['id'])) {
+      CRM_Utils_Hook::post('edit', 'Activity', $activity->id, $activity);
+    }
+    else {
+      CRM_Utils_Hook::post('create', 'Activity', $activity->id, $activity);
+    }
 
     return $result;
   }
diff --git a/CRM/Case/Form/Case.php b/CRM/Case/Form/Case.php
index 65532de6ff66..55d2122fe01b 100644
--- a/CRM/Case/Form/Case.php
+++ b/CRM/Case/Form/Case.php
@@ -354,7 +354,7 @@ public function postProcess() {
       $params['subject'] = $params['activity_subject'];
     }
     $caseObj = CRM_Case_BAO_Case::create($params);
-    $params['case_id'] = $caseObj->id;
+    $this->_caseId = $params['case_id'] = $caseObj->id;
     // unset any ids, custom data
     unset($params['id'], $params['custom']);