diff --git a/CRM/Contact/Selector.php b/CRM/Contact/Selector.php index 2143bb8ccdbe..13485776fc44 100644 --- a/CRM/Contact/Selector.php +++ b/CRM/Contact/Selector.php @@ -904,8 +904,8 @@ public function buildPrevNextCache($sort) { $cacheKey .= "_alphabet"; $this->fillupPrevNextCache($sort, $cacheKey); } - elseif ($firstRecord >= $countRow) { - $this->fillupPrevNextCache($sort, $cacheKey, $countRow, 500 + $firstRecord - $countRow); + elseif ($firstRecord + $pageSize >= $countRow) { + $this->fillupPrevNextCache($sort, $cacheKey, $countRow, max(500, $pageSize) + $firstRecord - $countRow); } return $cacheKey; }