I retrieve a field 3 levels deep which is working currently. The field which I currenly retrieve is going to become a dynamic field retrieved from custom metadata. How do I cast this to an id? I currently have the following but this isnt working:

Id conId = (Id) duInv.Invoice__r.BillingAccount__r.(Mdt.AccountContactId__c);

You would use the sObject.get method:

Id conId = (Id) duInv.Invoice__r.BillingAccount__r.get(Mdt.AccountContactId__c);

Assuming that Mdt is the custom metadata record, and AccountContactId__c is the lookup field.

  • Thanks didn't think of that. – Thomas Mar 12 '20 at 9:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.