I have been working on this problem awhile now and i'm not sure the direction I should go. I was pointed in the right direction but I am missing something.

I'm making a list view button on the accounts for my org. I am building our a visual force page that displays the selected accounts and then has a lookup/search field to change the owner. Hit save and all of the selected accounts owners switch, BUT the contacts stay the same. What is the best way to change the contacts over as well? It has been suggested to me to do an extension to the standardsetcontroller. I'm not sure about how to go about it. I don't believe a trigger set on the accounts would be the best idea for my org.

If I could write an extension that brings over the selected account's contacts and added to the "selected?" list and when save is hit, the changes will apply to both accounts and contacts.

Here is my code so far:

<apex:page standardController="Account" recordSetVar="accounts">
<apex:form >
    <apex:pageBlock >
        <apex:pageBlockSection >
            <apex:inputField value="{!Account.OwnerId}" />
        <apex:pageBlockTable value="{!selected}" var="Acct" >
            <apex:column value="{!Acct.Name}" />
            <apex:column value="{!Acct.OwnerId}"/>
        <apex:pageBlockButtons >
            <apex:commandButton action="{!save}" value="Save" />

  • Can you please add controller code Dec 18, 2016 at 0:41

1 Answer 1


I think the extension would be needed, to override the save method and set the OwnerChangeOption


Apex is not my area of expertise so someone else might have a better code- based approach

If you want to avoid code, you could potentially do this with visual workflow, but it would be challenging to avoid SOQL limits.

This post from MVP Andy Fawcett demonstrates how to pass in the selected IDs from a list to a sObject collection variable


It requires very light visualforce but no apex.

Getting all the contactIds in flow without hitting limits is tricky if someone selected 100+ accounts, because you can't filter a contact query by a list of account IDs and therefore would have to do a query within a loop.

You could in theory count the number of records that are passed in, and defer some of the processing to a wait element, which would get you a new set of limits but could take a few minutes to process the contact owner update.

There is an idea to allow for filtering fast lookups against a collection variable, but unless that happens code is probably the best option.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .