I have a contact trigger that passes Trigger.NewMap and Trigger.OldMap to an apex method, and then in the apex method, the following debug statement returns null for c.Account.Unit_Type__c:
for(Contact c: newMap.values()){
System.debug('MM ContactTrigger ++++ c.Account.Unit_Type__c = ' + c.Account.Unit_Type__c);
}
Question: I know I can do a separate SOQL query using the map as a WHERE condition to get a list of the contacts and the values of the related Account and Account.Field__c's, and then loop through that list instead of the newMap.values(), but is there any way to ADD that relationship data to the Trigger.NewMap
<Id,Contact>
map to allow me to traverse the relationships with dot notation while looping through newMap.values like I am trying to do in the code above?
I ask because there is already a lot of code in this class already using the newMap.values() loop but I now want to introduce a new conditional check against related account data. Ideally I'd like to do that without rewriting too much of the class and the easiest way would be if I could just traverse the relationship straight from the map. I am also considering a formula field on Contact but just wanted to check my options first.