function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
AlisonR3AlisonR3 

How do I limit my collection to 1,000 rows?

So I'm getting an error on some accounts when using the following extension controller. I'm not looking to get around the limit of 1,000, merely to restrict my collection to 1,000 so it will display. The following is my extension controller and despite limiting the query to 1,000 I still get an error on pages over 1,000.

 

public class AccountSalesActH {
    
    private final Account acct;
    
    public AccountSalesActH(ApexPages.StandardController stdController) {
        this.acct = (Account)stdController.getRecord();
    }
    public String getName() {
        return 'AccountSalesActH';
    }

        
    public Account getAccount() {
        Account[] acct = [select id, name, ownerid,
                    (select subject, who.name, createdby.name, whatid, whoid, activitydate, LVM__c, ownerid, lastmodifieddate from ActivityHistories 
                     where ownerid not in ('00530000000vpI1') order by activitydate DESC LIMIT 1000) //filter out marketing actvities 
                from Account
                where id = :ApexPages.currentPage().getParameters().get('id')]; if (acct.size()>0) {return acct[0];} else {return null;
    }

}}

 

ericmonteericmonte
can you paste the error? I believe it has something to do with the nested query, and the child records returns more than 1000.
AlisonR3AlisonR3

The error doesn't happen when there is less than 1,000 activities on the account that match the query conditions. The error only happens when there are more than 1,000 activities that match the query conditions. I've tested and those with 900 something activities that match, I don't get an error.

 

Here is an example of the error message I get:

 

Content cannot be displayed: INVALID_TYPE_FOR_OPERATION: entity type ActivityHistory does not support query

ericmonteericmonte
Can you try limit it to 999?
AlisonR3AlisonR3

I still get the error no matter what I set as LIMIT, even if its just 1 record.

AlisonR3AlisonR3

The error sometimes varies, here's an example of another error I get when the activity count is closer to 1,000 (when its super high - +3,000 I get that other error):

 

Content cannot be displayed: Collection size 1,542 exceeds maximum size of 1,000.

ericmonteericmonte
Can you tell me what exactly are you trying to accomplish in your visualforce page? Maybe there is a better solution and a change to your controller.
AlisonR3AlisonR3

Basically I have 2 controller extensions one that includes all activities logged by sales and one that includes all activities logged by marketing. I'm setting them up as separate related lists on the account so as to reduce the clutter when looking through the traditional related list: "Activity History".

AlisonR3AlisonR3
What I have set up achieves this perfectly, just this small error when there are too many activities. This seems like something simple I could modify in my controller so as to only return 1,000 records in the dataset.