apex-enterprise-patterns / fflib-apex-common

Common Apex Library supporting Apex Enterprise Patterns and much more!
BSD 3-Clause "New" or "Revised" License
910 stars 517 forks source link

Custom Metadata query - Metadata Relationship fields not supported #208

Open gribis opened 5 years ago

gribis commented 5 years ago

When custom metadata tables include references to related metadata (e.g. Entity or Field Definitions), fflib_QueryFactory throws an exception.

FeatureSetDefinitionmdt.ParentObjectr is not a lookup or master-detail field but is used in a cross-object query field.

The field definition for such a reference shows next to nothing of value; SoapType = String, isIdLookup = false, getRelationshipName = null. Short of avoiding the selector/queryfactory constructs, what are some simple fixes to the above conundrum?

wimvelzeboer commented 2 years ago

@daveespo @stohn777 Is there already some update about this problem? I ran into this issue again today. How do you advise we resolve this issue?

daveespo commented 1 year ago

@gribis or @wimvelzeboer -- can you provide a repro case (ideally a CMDT object definition and Selector class that reproduces this problem) ?

edgk1 commented 2 months ago

repro steps:

  1. create a new custom metadata object (Test__mdt)
  2. entity definition field (Entity__c)
  3. field definition field (Field__c) and select Entity as its controlling field
  4. create a new custom metadata record, set Entityc to custom object and Fieldc to custom field
  5. testSelector class:

    public with sharing class TestSelector extends fflib_SObjectSelector {
    public TestSelector() {
        super(false, true, true, false);
    }
    
    public List<Schema.SObjectField> getSObjectFieldList() {
        return new List<Schema.SObjectField>{ Test__mdt.Id };
    }
    
    public Schema.SObjectType getSObjectType() {
        return Test__mdt.SObjectType;
    }
    
    public List<Test__mdt> selectAll() {
    
        fflib_QueryFactory qf = newQueryFactory();
        qf.selectFields(new List<String>{'Entity__r.QualifiedApiName', 'Field__r.QualifiedApiName'});
    
        return Database.query(qf.toSOQL());
    
    }
    }
  6. try to call the method: new TestSelector().selectAll();
  7. exception thrown "fflib_QueryFactory.NonReferenceFieldException: Testmdt.Entityr is not a lookup or master-detail field but is used in a cross-object query field"
DfdezRNV commented 3 weeks ago

is this fixed somehow?