Skip to content
This repository has been archived by the owner on Jul 4, 2023. It is now read-only.

Are Selector classes really unable to retrieve parent fields? #6

Closed
ghost opened this issue Apr 4, 2014 · 3 comments
Closed

Are Selector classes really unable to retrieve parent fields? #6

ghost opened this issue Apr 4, 2014 · 3 comments

Comments

@ghost
Copy link

ghost commented Apr 4, 2014

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
        };
    }
@dieffrei
Copy link

dieffrei commented Apr 4, 2014

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()                
        }
    );  

@afawcett
Copy link
Contributor

afawcett commented Apr 4, 2014

Yes, this sample selector demonstrates this, i think the support for this can be improved though, https://github.com/financialforcedev/fflib-apex-common-samplecode/blob/master/fflib-sample-code/src/classes/OpportunitiesSelector.cls#L62.

Btw, take a look at the new repo where the latest library for the patterns is being progressed. 👍 https://github.com/financialforcedev/fflib-apex-common

@afawcett
Copy link
Contributor

afawcett commented Apr 9, 2014

@rsoesemann Can you take a look and feedback on the migrated issue here apex-enterprise-patterns/fflib-apex-common#4

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants