+ Start a Discussion
Alex Valavanis 10Alex Valavanis 10 

Visual Force change Contact Ownerhip

Hello,

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:pageBlockButtons>
        <apex:pageBlockTable value="{!accounts}" var="A">
            <apex:column headerValue="Name">
                <apex:inputField value="{!A.name}"/>
            </apex:column> 
            <apex:column headerValue="Owner">
                <apex:inputField value="{!A.OwnerId}"/>
            </apex:column>
            <apex:inlineEditSupport event="ondblClick" showOnEdit="saveButton,cancelButton" />
       </apex:pageBlockTable>         
    </apex:pageBlock>
  </apex:form>
</apex:page>

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

Greetings!

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

https://developer.salesforce.com/forums/?id=906F0000000kBLMIA2

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

Warm Regards,
Shirisha Pathuri