jongpie / NebulaFramework

A development framework for Salesforce's Apex language & the Force.com platform
MIT License
46 stars 15 forks source link

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

Open derroman opened 3 years ago

derroman commented 3 years ago

Hi @jongpie and @jamessimone

Similar to the issue mentioned over here: https://github.com/jamessimone/apex-dml-mocking/issues/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 commented 3 years ago

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 https://github.com/jamessimone/apex-dml-mocking/issues/1#issuecomment-764743723 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?! ;-)