Code Monkey home page Code Monkey logo

Comments (3)

afawcett avatar afawcett commented on August 14, 2024

See original issue comment here, certinia/df12-apex-enterprise-patterns#6 (comment)

Having centralised SOQL Builders is of immensive use, but not being able to query parent fields limits its usage in enterprise apps very much

This doesn't even compile

    public List<Schema.SObjectField> getSObjectFieldList() {
        return new List<Schema.SObjectField> {
            ChildRecord__c.Name,
            ChildRecord__c.Parent__c,
            ChildRecord__c.Parent__r.GranParent__c
        };
}

This compiles but doesn't query the defined fields:

    public List<Schema.SObjectField> getSObjectFieldList() {
        return new List<Schema.SObjectField> {
            ChildRecord__c.Name,
            ChildRecord__c.Parent__r.Id,
            ChildRecord__c.Parent__r.GranParent__r.Id
        };
    }

from fflib-apex-common.

afawcett avatar afawcett commented on August 14, 2024

See original comment here, certinia/df12-apex-enterprise-patterns#6 (comment)

It's correct, the getSObjectFieldList method objective is list all fields from current SObject.

When you build your queries use getRelatedFieldListString('relationship_name'), to access parent fields, like this:

    String query = String.format(
        ' SELECT {0},{1}' + 
        ' FROM {2}' +
        ' WHERE Id IN :idSet' +
        ' ORDER BY {3}',
        new List<String>{
            getFieldListString(),
            setInvestSelector.getRelatedFieldListString('Parent__r'),
            getSObjectName(),               
            getOrderBy()                
        }
    );  

from fflib-apex-common.

afawcett avatar afawcett commented on August 14, 2024

Since we released the fflib_QueryFactor a couple of weeks ago, i've been working on an update to the above pattern for handling related fields in the query. While the above example will still work, we will also support the ability to use the Query Factory, as a preview here is the code i will updating in the sample app repo shortly...

public List<Opportunity> selectByIdWithProducts(Set<ID> idSet)
{
    fflib_QueryFactory opportunitiesQueryFactory = newQueryFactory();

    fflib_QueryFactory lineItemsQueryFactory = 
        new OpportunityLineItemsSelector().
            addQueryFactorySubselect(opportunitiesQueryFactory);

    new PricebookEntriesSelector().
        configureQueryFactoryFields(lineItemsQueryFactory, 'PricebookEntry');
    new ProductsSelector().
        configureQueryFactoryFields(lineItemsQueryFactory, 'PricebookEntry.Product2');
    new PricebooksSelector().
        configureQueryFactoryFields(lineItemsQueryFactory, 'PricebookEntry.Pricebook2');

    return (List<Opportunity>) Database.query(
        opportunitiesQueryFactory.setCondition('id in :idSet').toSOQL());
}

from fflib-apex-common.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.