You need to sign in to do that
Don't have an account?
Volly
Map user custom field to custom object via trigger
I have a trigger that pulls information from the owner of the account and places it in the custom object. There are 7 fields in the user object that I need to pull data from. 3 are standard objects, 4 are custom objects. My question is how do I pull the custom field information from the account owner's user record to the custom object fields?
My code:
trigger Escalation_Trigger on test1__c (before insert, before update) { list<id> accountIds = new list<id>(); for (test1__c xxx : trigger.new) accountIds.add(xxx.account__c); //Map works fine on standard objects in User object. map<id,account> approvers = new map<id,account>([select id, owner.id, owner.manager.id, owner.UserRole.id from account where id in :accountIds]); //create map of Escalation Manager, Escalation Manager email, DDSM email, LOB email //Receiving error on line 12. I do not understand why. map<id,account> managersescalation = new map<id,account>([select owner.Escalation_Manager_Email__c, DDSM_email__c, LOB_Manager_s_email__c, RP_email__c from account where id in :account]); for (test1 xxx : trigger.new) { Account approversAccount = approvers.get(xxx.account__c); // The first 3 work fine. THey are standard fields on the user object if (xxx.Approving_M__c == null) xxx.Approving_M__c = approversAccount.owner.id; if (xxx.Approving_Manager__c == null) xxx.Approving_Manager__c = approversAccount.owner.manager.id; if (xxx.Owner_Role__c == null) xxx.Owner_Role__c = approversAccount.owner.UserRole.id; //---------------- // These 4 do not work. I do not know why. // Do I reference the field name or API name? if (xxx.Escalation_Email__c == null) xxx.Escalation_Email__c = managersescalationAccount.owner.Escalation_Manager_Email__c.id; if (xxx.DDSM_Email__c == null) xxx.DDSM_Email__c = managersescalationAccount.owner.DDSM_Email__c; if (xxx.LOB_Manager_s_email__c == null) xxx.LOB_Manager_s_email__c = managersescalationAccount.owner.LOB_Manager_s_email__c.id; if (xxx.RP_email__c == null) xxx.RP_email__c = managersescalationAccount.owner.RP_email__c.id; } }
Change the SOQL to:
That should do the trick
All Answers
Change the SOQL to:
That should do the trick
Tried what you suggested, I received this error:
I also tried owner.Escalation_Email__c and owner.Escalation_Email__r. Both attempts made no difference.
Opps! I had it labled wrong. What you gave me works great. Thanks!