You need to sign in to do that
Don't have an account?
jeffdonthemic
Trigger - Related Object Null?
I have the following trigger that sets a field on the Account based upon the owner's settings. The Owner object appears to be blank during the execution of the trigger?? Running the code from Eclipse, I can see that the Owner is not null and the values should be set properly.
Any idea why the Owner reference is null?
Any idea why the Owner reference is null?
Code:
trigger UpdateBusinessUnit on Account (before insert, before update) { for (Account a : Trigger.new) { System.debug('Industry: '+a.Industry__c); System.debug('SubLocation: '+a.Owner.SubLocation__c); // <----- returned as null— System.debug('Location: '+a.Owner.Location__c); // <----- returned as null– if (a.Industry__c != null && a.Owner.SubLocation__c != null && a.Owner.Location__c != null) { // set the value a.Business_Unit__c = a.Industry__c+a.Owner.SubLocation__c+a.Owner.Location__c; } else { a.Business_Unit__c = ''; } } }
After doing the trigger, your new map will have the data you are interested in referencing. Or, you could use just a list/array if that's all you're concerned about accessing, but the map makes it a bit nicer in terms of referencing the accounts.