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
Rakhi B 10Rakhi B 10 

When ever we change the contact lastname ,customer portal user lastname also update

SandhyaSandhya (Salesforce Developers) 
Hi,

Refer below link which has the sample code for the same.

https://success.salesforce.com/ideaView?id=087300000006tto
 
Please mark it as Solved if my reply was helpful. It will make it available for other as the proper solution.
 
Thanks and Regards
Sandhya
 
 
Rakhi B 10Rakhi B 10
Hi Sandhya Using Trigger how we can do.. Thanks and Regards Rakhi
Ajay K DubediAjay K Dubedi
Hi Rakhi,

Please refer to the below code. Hope this helps you.

//Apex Class

public class CustomerPortalUpdate {
public static void updateUserLName(List<Contact> contactList)
{
    Set<Id> contactIdSet = new Set<Id>();
    for(Contact cont: contactList)
    {
        contactIdSet.add(cont.Id);
    }
    
    List<User> userList = new List<User>();
    userList = [SELECT ContactId,LastName FROM User WHERE ContactId IN:contactIdSet];
    
    List<User> updateUserList = new List<User>();
    
    for(Contact con_iterate: contactList)
    {
        for(user u_iterate: userList)
        {
            u_iterate.LastName = con_iterate.LastName;
            
            updateUserList.add(u_iterate);
        }
    }
    update updateUserList;
}
}

//Trigger

trigger UpdateCustomerPortal on Contact (after update) {
     CustomerPortalUpdate.updateUserLName(Trigger.New);
}

Please mark it as best answer if it helps you.

Thank You,
Ajay Dubedi
Rakhi B 10Rakhi B 10
Hi Sandhya Using Trigger how can do this .. Thanks and Regards Rakhi