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
Arun AdepuArun Adepu 

update field values from user to contact

Hi Friends,

I have requirement like this..
i have fields in user are firstname, lastname, title and contact fields are firstname, lastname and title.
when ever i update field values in user that also update contact fields if contacts are partner contacts..
please resolve immediately...
sfdcMonkey.comsfdcMonkey.com
hi Arun
write a trigger on user object
try this trigger code
trigger UpdateContactAsPortalUser on User (after update) {
Set<Id> contactIds = new Set<Id>();

for (User u : Trigger.new) {
  if (u.ContactId != null)
   contactIds.add(u.ContactId);
}

if (contactIds.size() > 0) {

  List<Contact> contacts = [select id, FirstName, LastName ,Title from Contact where Id in :contactIds];
for(User u : trigger.new){
  for (Contact c : contacts) {
   c.FirstName = u.FirstName;
   c.LastName = u.LastName;
   c.Title = u.Title;   
  }
  }
  update contacts;
}

}
Thanks
Mark it best answer if it helps you .:)
 
Arun AdepuArun Adepu
thanks Ayush for your answer...