NebulaQueryAndSearch icon indicating copy to clipboard operation
NebulaQueryAndSearch copied to clipboard

Add a way to query multiple parent-level fields, using fewer lines of code

Open jongpie opened this issue 2 years ago • 0 comments

With the current implementation, if you want to query multiple fields from a parent object, the code required is somewhat lengthy:

Query accountQuery = new Query(Schema.Case.SObjectType)
    .addField(new SOQL.QueryField(new List<Schema.SObjectField>{
        Schema.Case.AccountId,
        Schema.Account.AnnualRevenue
    }))
    .addField(new SOQL.QueryField(new List<Schema.SObjectField>{
        Schema.Case.AccountId,
        Schema.Account.NumberOfEmployees
    }));

System.debug(accountQuery.getQuery());
System.debug(accountQuery.getResults());

In the above example, each parent-level field has to have the chain of fields passed to a constructor for SOQL.QueryField() - it'd be nice if some of the field chain could be reused so Apex devs can write less code to get the same functionality.

jongpie avatar Jan 16 '23 16:01 jongpie