1

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:pageBlockSection>
        <apex:pageBlockTable value="{!selected}" var="Acct" >
            <apex:column value="{!Acct.Name}" />
            <apex:column value="{!Acct.OwnerId}"/>
        </apex:pageBlockTable>
        <apex:pageBlockButtons >
            <apex:commandButton action="{!save}" value="Save" />
        </apex:pageBlockButtons>
    </apex:pageBlock>
</apex:form>

  • Can you please add controller code – Santanu Boral Dec 18 '16 at 0:41
0

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

https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_header_ownerchangeoptions.htm

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

https://www.google.com/amp/s/andyinthecloud.com/2014/06/04/more-power-to-your-flows-in-summer14/amp/

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.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.