apex-enterprise-patterns/force-di

Apex Binding__mdt record to custom sobject fails

ImJohnMDaniel opened this issue · 0 comments

An exception is thrown when the di_Binding tries to load a Binding__mdt record that has the Binding Object (Binding__mdt.BindingObject__c) field mapped to a custom SObject (i.e. Widget__c).

Steps to reproduce

  • Setup Force-DI project
  • Create new Binding__mdt record.
    • QualifiedAPIName, DeveloperName, BindingSequence__c == some arbitrary value
    • Type__c == Apex
    • To__c == random string
    • BindingObject__c == Custom SObject like Widget__c
  • Execute anonymous: RuntimeBindingDemoOrg.run();

Exception seen

ERROR:  Execution failed.

 ▸    ERROR: System.InvalidParameterValueException: Invalid sobject provided.
 ▸    The Schema.describeSObject() methods does not support the 01i3b00000034c4
 ▸    sobject as a parameter. The sobject provided does not exist.
 ▸    ERROR: Class.di_Injector.CustomMetadataModule.configure: line 147, column
 ▸    1
 ▸    Class.di_Binding.Resolver.loadBindings: line 265, column 1
 ▸    Class.di_Binding.Resolver.get: line 277, column 1
 ▸    Class.di_Injector.getInstance: line 87, column 1
 ▸    Class.di_Injector.getInstance: line 60, column 1
 ▸    Class.RuntimeBindingDemoOrg.WelcomeApp.<init>: line 16, column 1
 ▸    Class.RuntimeBindingDemoOrg.run: line 30, column 1

Comments

The issue appears to be that when CMDT records with fields of the data type "Metadata Relationship(Entity Definition)", the value returned on that field in Apex will be the API name of the SObject if that SObject is a Standard SObject. If it contains the value of a Custom SObject, then the internal SObject Record ID is returned instead. That is not accepted on the Schema.describeSObject() method call in the di_Injector.CustomMetadataModule.configure() method call on line 147.