You need to sign in to do that
Don't have an account?
Unable to get owner name as string when owner is queue or user
Hey SFDC Community!
I am having an issue with a trigger where I am unable to get the Owner.Name as a string when the owner value is changed. When I use OwnerId the field that I am trying to populate will work but when I use Owner.Name it gets populated as blank. I know this should work but for some reason I am running into issues over it. See the trigger below and let me know what you think. I have highlighted and underlined the line where I have the Owner.Name. Thanks in advance!
I am having an issue with a trigger where I am unable to get the Owner.Name as a string when the owner value is changed. When I use OwnerId the field that I am trying to populate will work but when I use Owner.Name it gets populated as blank. I know this should work but for some reason I am running into issues over it. See the trigger below and let me know what you think. I have highlighted and underlined the line where I have the Owner.Name. Thanks in advance!
trigger UpdateOFR on Feature_Request__c (after update, after insert) { if (trigger.isUpdate){ Set<Id> setFRchangeIds = new Set<Id>(); for (Feature_Request__c fr : trigger.new){ Feature_Request__c frOldFR = trigger.oldMap.get(fr.Id); boolean frIsChanged = (fr.Feature_Request_Status__c != frOldFR.Feature_Request_Status__c || fr.Target_Release__c != frOldFR.Target_Release__c || fr.OwnerId != frOldFR.OwnerId); if (frIsChanged){ setFRchangeIds.add(fr.Id); } } if (setFRchangeIds.isEmpty() == false){ List<Opportunity_Feature_Request__c> listOFR = [Select Id, Feature_Request__c From Opportunity_Feature_Request__c where Feature_Request__c IN:setFRchangeIds]; for (Opportunity_Feature_Request__c ofr : listOFR){ Feature_Request__c fr = trigger.newMap.get(ofr.Feature_Request__c); ofr.Feature_Request_Owner__c = fr.Owner.Name; ofr.Feature_Request_Status__c = fr.Feature_Request_Status__c; ofr.Feature_Request_Target_Release__c = fr.Target_Release__c; } if (listOFR.isEmpty() == false){ update listOFR; } } } }
In the trigger.New you can't get the parent field name. If you want the parent level information you have to write SOQL query to get the name of the field.