Skip to content

fflib_QueryFactory subqueries produce incorrect soql #26

@rsoesemann

Description

@rsoesemann

I tried to create a query that also fetches related child records but I was unable as the syntax of building such subqueries doesn't produce correct SOQL. Even test methods from the library did work.

Account acct = new Account();
acct.Name = 'testchildqueriesacct';
insert acct;
Contact cont = new Contact();
cont.FirstName = 'test';
cont.LastName = 'test';
cont.AccountId = acct.Id;
insert cont;

String soql = new fflib_QueryFactory(Account.SObjectType)
    .selectField('Name')
    .subselectQuery(Contact.SObjectType)
    .selectField('FirstName')
    .toSoql();

System.debug(soql);
List<Account> accounts = Database.query(soql);

Prints out this incorrect soql

SELECT FirstName FROM Contacts

and throws this exception:

System.QueryException: sObject type 'Contacts' is not supported. If you are attempting to use a
custom object, be sure to append the '__c' after the entity name. Please reference your WSDL or the > describe call for the appropriate names.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions