+ Start a Discussion
Alex Valavanis 10Alex Valavanis 10 

Visual Force change Contact Ownerhip


I created a visualforce and a custom button which allows the users to change their account ownership from one user to another user. What i would like to add to this code is allow them to change the contact owner as well. Could you please assist me? The Contact Owner Field name is "OwnerId" as you would expect.

Below is my current visual force code and a screenshot of what i want to accomplish.
<apex:page standardController="Account" recordSetVar="accounts" tabStyle="Account" sidebar="false" lightningStylesheets="true">
    <apex:form >
        <apex:pageBlock title="Edit Accounts" mode="edit">
            <apex:pageMessages />
            <apex:pageblockButtons location="top">
                <apex:commandButton value="Save" action="{!Save}" id="saveButton"/>
                <apex:commandButton value="Cancel" action="{!cancel}" id="cancelButton"/>
        <apex:pageBlockTable value="{!accounts}" var="A">
            <apex:column headerValue="Name">
                <apex:inputField value="{!A.name}"/>
            <apex:column headerValue="Owner">
                <apex:inputField value="{!A.OwnerId}"/>
            <apex:inlineEditSupport event="ondblClick" showOnEdit="saveButton,cancelButton" />

User-added image
ShirishaShirisha (Salesforce Developers) 
Hi Alex,


Please refer the sample code provided in the below thread to change the Account and Contact owners.


Kindly mark it as best answer if it helps so that it can help others in the future.

Warm Regards,
Shirisha Pathuri