I'm trying to grab the oldest customer, using the customer repository from the database.

Here's my code so far:

    // if custom is active 
    $isActivefilter = $this->filter

    $isActiveFilterGroup = $this->filterGroup

    // ========== AND ========== //

    // if customer has an account id = $user
    $accountIdFilter = $this->filter

    $accountIdFilterGroup = $this->filterGroup

    // ========== SORT BY CREATED AT ========== // 

    // setting the sort order to ascending will bring the oldest records to the top 
    $sortByCreatedAt = $this->sortOrder

    $searchCriteria = $this->searchCriteria
        ->setFilterGroups([$isActiveFilterGroup, $accountIdFilterGroup])

So before I set the search criteria in getList($searchCriteria), I want to make sure I'm only querying for one result like limit 1

Is there a way to do that using the repository and search criteria?

1 Answer 1


Figured it out.


$searchCriteria = $this->searchCriteria

->setPageSize() limits the amount of entities in the query.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.