You need to sign in to do that
Don't have an account?

how to reference lookup name field in apex class?
public static void checkDestination(Map<Id, order__c> newOrders, Map<Id, order__c> oldOrders){ for(Id id : newOrders.keyset()){ if(newOrders.get(id).Destination__c != oldOrders.get(id).Destination__c && newOrders.get(id).Destination__r.Name.contains(‘OverSeas’)){ newOrders.get(id).Received__c =True; } } }Simple class but when I use contains() in my lookup reference: destination__r.Name, it throws an error:
Unable to de-reference a null object
How can I write my class that if my destination lookup has the word “overseas” in it, it will set my orders received field to be true?
Could you please try this -
You need to re-query in order to obtain fields on the parent record. Feel free to add the other fields to the SOQL too. I like to use a "relatedData" map so that I don't lose the records in the trigger:
+100! I like that idea of relatedDataMap. By the way I think you are using Book Quotes instead of Typewriter Quotes for the OverSeas word.
Yes - copied from the original post. Sharp eye!