You need to sign in to do that
Don't have an account?
Collaborative e
Pass Account Owner Info to Account Object
I need to pass the Account Owner's phone number to a custom field on the account object. Is there a simple way or code clip?
function readOnly(count){ }
You need to sign in to do that
Don't have an account?
You could write an apex trigger to identify when the owner is changed, retrieve the owner's phone and set a custom field with that phone number value. Here is some sample code to get you started...
trigger enter_trigger_name_here on Account (before insert, before update) { 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 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].custom_phone_field__c = users.get(Trigger.new[a].OwnerId).phone; } } }
All Answers
You could write an apex trigger to identify when the owner is changed, retrieve the owner's phone and set a custom field with that phone number value. Here is some sample code to get you started...
trigger enter_trigger_name_here on Account (before insert, before update) { 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 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].custom_phone_field__c = users.get(Trigger.new[a].OwnerId).phone; } } }