function readOnly(count){ }
Don't have an account?
Search for an answer or ask a question of the zone or Customer Support.
You need to sign in to do that
Sign in to start searching questions
Signup for a Developer Edition
Sign in to start a discussion
Hi Rakhi,Please try the below code for update username in contact.
public class ContactUpdateWithUser { public static void isAccount(List<Contact> conList){ String userName = UserInfo.getName(); system.debug('User Name ------------>'+UserName); if(conList != NULL){ Map<Id,User> accMap = new Map<Id,User>([SELECT id,Name FROM User WHERE Name = : userName ]); for(contact cont : conList) { cont.FirstName = accMap.get(cont.OwnerId).Name; } try{ update accMap.Values(); }catch(DMLException e){ system.debug(e.getMessage()); } } } } Trigger Class trigger TestAccountContact on Contact (before insert , before update) { if((trigger.IsInsert && trigger.isBefore) || (trigger.isBefore && trigger.isUpdate)){ ContactUpdateWithUser.isAccount(trigger.new); } }
Hi Rakhi,
Please try the below code for update username in contact.
Please make it best if it helps you.
Thanks
Ajay Dubedi
Trigger contactUpdate on Contact(Before update){
for(Interger i=0; i<trigger.new.size(); i++)
{
if(trigger.new[i].FirstName != trigger.old[i].FirstName){
trigger.new[i].OwnerId = '<Desired OwnerId>';
}
}
}