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
Mike AgresMike Agres 

Trigger on User to Update that User's Contacts

Use Case: if certain field values on a User record changes, I want that change to appear in corresponding fields on all the Contact records that this user owns.

I figure I need to create this trigger on the User object, but how do I call that User's Contact records to update their values?
Chandrashekhar GoudChandrashekhar Goud
Apex Class for both update and create:
global class usertocontact {
     /* Code for Update a contact using User */
    public static void usertocon(Set<Id> userIds) {
        List<User> user = [select Id, firstname, lastname, email from user where Id IN :userIds];
        List<contact> cons = new List<contact>();
        for (User usr : User) {
            contact c = new contact ();
            c.FirstName = usr.FirstName;
            c.LastName = usr.LastName;
        update cons;
    /* Code for create a contact using User */
    public static void usertocon() {
        List<Contact> contacts = new List<Contact>();
        List<User> user = [select Id, firstname, lastname, email from user ];
        for (User u: User){
            Contact c = new Contact();
            c.FirstName = u.FirstName;
            c.LastName = u.LastName;
        insert contacts;
/*Trigger for Create */
trigger NewContactOnUser on User (before insert) {

/*Trigger for update*/
trigger usertoContact on User (after insert) {


Hetvi SalesforceHetvi Salesforce
Hello @ Mike Agres, I have the Same Task... Did You get any Solution?