Skip to content

Sample code to query related records //Suggested Wiki Update #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
bdJohnson72 opened this issue Mar 16, 2023 · 0 comments
Open

Sample code to query related records //Suggested Wiki Update #8

bdJohnson72 opened this issue Mar 16, 2023 · 0 comments

Comments

@bdJohnson72
Copy link

If we need our query to include related record data we create an instance of our parent selector. In this case, Accounts and provide the query factory with the relationship.

 public List<Contact> selectWithAccountData(){
        fflib_QueryFactory contactQueryFactory = newQueryFactory();
        new AccountSelector().configureQueryFactoryFields(contactQueryFactory,
                Contact.AccountId.getDescribe().getRelationshipName());

        return Database.query(contactQueryFactory.toSOQL());
    }

Running this query will generate the following query string:
SELECT Account.AccountNumber, Account.Id,
Account.Industry, Account.Name, Account.NumberOfEmployees,
Account.Rating, AccountId,
Email, Id, Name, Phone, Title
FROM Contact
ORDER BY
Name ASC
NULLS FIRST

@bdJohnson72 bdJohnson72 changed the title Sample code to query related records Sample code to query related records //Suggested Wiki Update Mar 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant