at4dx icon indicating copy to clipboard operation
at4dx copied to clipboard

TestDataSupplementer misuses BindingSObject__c for custom SObjects

Open jonnypetraglia opened this issue 3 years ago • 1 comments

TestDataSupplementer acts like BindingSObject__c will always contain the developer name of the SObject, but that's not the case.

SObjectType sobjType = Schema.getGlobalDescribe().get( String.isNotBlank(tds_mdt.BindingSObject__c) ? tds_mdt.BindingSObject__c : tds_mdt.BindingSObjectAlternate__c );

For standard objects such as Account or Contact, BindingSObject__c will just be "Account" or "Contact" respectively, which is no problem. But if the BindingSObject__c is not standard, that field value contains an ID for the Entity Definition like "01I1k00000143aP", and because the global schema describe is keyed by DeveloperName, sobjType will always be null.

So what we are really looking for is bindingConfig.BindingSObject__r.QualifiedApiName but this is not accessible in TestDataSupplementer.cls due to using di_Injector.Org.Bindings.byName(ITestDataSupplement.class.getName()).get() to retrieve the MDT.

That's the extent of the problem as I see it. The workaround is obviously to use BindingSObjectAlternate__c. I don't know another solution up front, unless there's a way to get an SObjectType by its 01I ID.

jonnypetraglia avatar Jul 27 '21 20:07 jonnypetraglia

Hi @jonnypetraglia

I've read the issue and reviewed the existing feature and cannot duplicate the issued. First please double-check the usage of the TestDataSupplement example in the AT4DX Samples repo [1] as a comparison. Second if the problem persists, would you please provide a concise example that I could push and debug in a scratch org.

Thanks.

[1] https://github.com/apex-enterprise-patterns/at4dx-samplecode/blob/master/sfdx-source/reference-implementation-marketing/main/classes/supplementers/MarketingFieldsForAccountsSupplementer.cls

stohn777 avatar Aug 03 '21 20:08 stohn777