diff --git a/CRM/DataprocessorSearch/Form/AbstractSearch.php b/CRM/DataprocessorSearch/Form/AbstractSearch.php
index fb71e5d380b445b66e9591a5fe99a2be671ff6bd..c06983af790bb79dc7de600c815cddcb08051d16 100644
--- a/CRM/DataprocessorSearch/Form/AbstractSearch.php
+++ b/CRM/DataprocessorSearch/Form/AbstractSearch.php
@@ -269,6 +269,8 @@ abstract class CRM_DataprocessorSearch_Form_AbstractSearch extends CRM_Dataproce
             'data' => $record,
           );
           $ids[] = $row['id'];
+        } else {
+          $ids[] = $row['id'];
         }
 
         $rows[] = $row;
diff --git a/CRM/DataprocessorSearch/Form/ActivitySearch.php b/CRM/DataprocessorSearch/Form/ActivitySearch.php
index e9686ea28e02b38599319c59c72da6c1505cc52f..52467c477de1a602ad1ecf28fbf9a9482f9f82bd 100644
--- a/CRM/DataprocessorSearch/Form/ActivitySearch.php
+++ b/CRM/DataprocessorSearch/Form/ActivitySearch.php
@@ -8,6 +8,15 @@ use CRM_Dataprocessor_ExtensionUtil as E;
 
 class CRM_DataprocessorSearch_Form_ActivitySearch extends CRM_DataprocessorSearch_Form_AbstractSearch {
 
+  /**
+   * The params that are sent to the query.
+   *
+   * @var array
+   */
+  protected $_queryParams;
+
+  protected $activity_ids;
+
 
   /**
    * Returns the name of the default Entity
@@ -99,4 +108,29 @@ class CRM_DataprocessorSearch_Form_ActivitySearch extends CRM_DataprocessorSearc
     return $this->_taskList;
   }
 
+  /**
+   * Return altered rows
+   *
+   * Save the ids into the queryParams value. So that when an action is done on the selected record
+   * or on all records, the queryParams will hold all the activity ids so that in the next step only the selected record, or the first
+   * 50 records are populated.
+   *
+   * @param array $rows
+   * @param array $ids
+   *
+   */
+  protected function alterRows(&$rows, $ids) {
+    $this->activity_ids = $ids;
+    $this->_queryParams[0] = array(
+      'activity_id',
+      '=',
+      array(
+        'IN' => $this->activity_ids,
+      ),
+      0,
+      0
+    );
+    $this->controller->set('queryParams', $this->_queryParams);
+  }
+
 }
\ No newline at end of file