Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

Issue with a big set of Ids in a where clause #87

Open
derroman opened this issue Jan 22, 2021 · 1 comment
Open

Issue with a big set of Ids in a where clause #87

derroman opened this issue Jan 22, 2021 · 1 comment

Comments

@derroman
Copy link

Hi @jongpie and @jamessimone

Similar to the issue mentioned over here: jamessimone/apex-dml-mocking#2 (which has been fixed by @jamessimone ) I discover the same issue also in this framework (which is pretty cool by the way)

So, in my scenario I do a query on account team member by providing a huge list of account ids

I've created a small Repository which has a single method:

public with sharing class AccountTeamMemberRepository extends SObjectRepository {

    public override SObjectType getSObjectType() {
        return Schema.AccountTeamMember.SObjectType;
    }
    
    public List<AccountTeamMember> getAccountTeamMembersByAccountIds(Set<Id> accountIds) {
        return new SObjectQueryBuilder(this.getSObjectType())
                .addAllFields()
                .filterBy(new QueryFilter().filterByField(new QueryField(Schema.AccountTeamMember.AccountId), QueryOperator.IS_IN, accountIds))
                .getQueryResults();
    }
}

When I run this in Anonymous Apex with a set of more than 12 account Ids, I get an error

//anonymous apex
AccountTeamMemberRepository repo = new AccountTeamMemberRepository();
repo.getAccountTeamMembersByAccountIds(new Set<Id>{
        '0010O0000265ZliQAE', '0010O000028mXFFQA2', '0010O000028peYlQAI', '0010O000028pexAQAQ', '0010O00002B6sgBQAR', '0010O00002B78G6QAJ', '0010O00002B7AceQAF', '0010O00002B7AgWQAV', '0010O00002B7FilQAF', '0010O00002ENWYuQAP', '0010O00002ENXJDQA5', '0010O00002Md4QBQAZ', '0010O00002MdnnFQAR', '0010O00002OVySHQA1'    
});
Error on line 126, column 1: System.QueryException: invalid ID field: ...
Class.QueryBuilder.executeQuery: line 126, column 1
Class.QueryBuilder.doGetQueryResults: line 97, column 1
Class.SObjectQueryBuilder.getQueryResults: line 210, column 1

When I debug the query right before execution we can clearly see, that the last "entry" is just some dots, and most of the Ids are missing

SELECT account.name, accountaccesslevel, accountid, automaticallyadded__c, caseaccesslevel, contactaccesslevel, createdby.name, createdbyid, createddate, id, isdeleted, lastmodifiedby.name, lastmodifiedbyid, lastmodifieddate, opportunityaccesslevel, photourl, projectaccesslevel__c, systemmodstamp, teammemberrole, title, user.name, userid
FROM AccountTeamMember
WHERE AccountId IN ('0010O0000265ZliQAE', '0010O000028mXFFQA2', '0010O000028peYlQAI', '0010O000028pexAQAQ', '0010O00002B6sgBQAR', '0010O00002B78G6QAJ', '0010O00002B7AceQAF', '0010O00002B7AgWQAV', '0010O00002B7FilQAF', '0010O00002ENWYuQAP', '...')

mhh... ?! :-(

@derroman
Copy link
Author

derroman commented Jan 22, 2021

Fun fact: when I change the parameter from Set to List it works smoothly.

public with sharing class AccountTeamMemberRepository extends SObjectRepository {

    public override SObjectType getSObjectType() {
        return Schema.AccountTeamMember.SObjectType;
    }
    //changed from Set to List
    public List<AccountTeamMember> getAccountTeamMembersByAccountIds(List<Id> accountIds) {
        return new SObjectQueryBuilder(this.getSObjectType())
                .addAllFields()
                .filterBy(new QueryFilter().filterByField(new QueryField(Schema.AccountTeamMember.AccountId), QueryOperator.IS_IN, accountIds))
                .getQueryResults();
    }
}

Based on this comment by @jamessimone here jamessimone/apex-dml-mocking#1 (comment) and here https://github.com/jamessimone/apex-dml-mocking/blob/384ce721fc1ef46c251e590b7b2fd521dc81d9d6/force-app/repository/Query.cls#L100 I assume Sets in apex are kind of difficult to handle?! ;-)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant