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
TwrightTwright 

Updating Custom Fields with an Control. Need to be able to point at the Users record

So I am new at the developer Sites. I m looking to get some help with a request that came across my desk. I am looking to write a s-control or an Apex trigger that will lookup the Owners information to pull in the Owners Email on the account records. I know this can be done simple, Just not sure how to start out. Which is easier to an S-control or a Apex trigger. I am not a developer by far. I need to know how to start them out and how to reference the owners users record within the account. Then what Tag I can use to bring that information to update a new field.

 

Can someone please help the new guy out?

 

Thanks

Travis Wright

Collaborative eCollaborative e

Travis,

 

I had the same question awhile back. Here's an example of an Apex Trigger I built to pull basic account information into hidden fields from the account owner record to the opportunity record. Same idea applies to what you want to do.

 

 

List<Id> ownerIds = new List<Id>{}; for(Integer a= 0; a<Trigger.new.size(); a++){ if(Trigger.isUpdate && Trigger.old[a].OwnerId!=Trigger.new[a].OwnerId ) ownerIds.add(Trigger.new[a].OwnerId); else ownerIds.add(Trigger.new[a].OwnerId); } Map<Id, User> users = new Map<Id,User>([select id, Phone, MobilePhone, Email from user where id in :ownerIds]); for(Integer a= 0; a<Trigger.new.size(); a++){ if(users.get(Trigger.new[a].OwnerId) != null){ Trigger.new[a].Account_Owner_Phone_Number__c = users.get(Trigger.new[a].OwnerId).MobilePhone; Trigger.new[a].Account_Owner_E_mail__c = users.get(Trigger.new[a].OwnerId).Email; Trigger.new[a].Account_Owner_Phone__c = users.get(Trigger.new[a].OwnerId).Phone; } } }

 You'll need to write a basic test method before you can push this to your live org.

 

I hope this helps.

 

Kevin