function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Apex Trigger for Manager Email


I am attempting to write an Apex trigger to look up the ManagerID for the record owner, the post the Manager email address into a custom field on the current record.


I'm new to Apex and having difficulty developing this code, which seems like it should be relatively simple.


Anyone have examples of such functionality?




I need to do exactly the same thing and so far triggers don't seem to be my strong suit.  If you figure this out I would love to know how you did it.  If I figure it out I willl let you know.

The steps I followed to do this are:


Create a custom LOOKUP field on the OBJECT (let's call it AssignedOwner)

Create an APEX trigger to set the LOOKUP field as the record OWNER (AssignedOwner__c = Account.OwnerID)

Create an email field on the OBJECT (let's call it ManagerEmail)

Create a workflow update to run a FIELD UPDATE on the ManagerEmail and reference AssignedOwner__r.Manager.Email


Here's the trigger - I think you can figure out the rest (It's probably crappy code, so developers, please recommend fixes - but it gets the job done!)


trigger MyObjectOwnerLookupThingy on Account(before insert, before update) {
    For (Account Account_This : System.Trigger.New)
        Account_This.AccountOwner__c = Account_This.OwnerID;