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
Mallik VemuguntaMallik Vemugunta 

Custom Account update button on contacts

I had the below code to display the selected contacts from the account page related list, looks like my !selected is not working, can someone help on this.
<apex:page StandardController="Contact" recordSetVar="contacts">
    <apex:form >
        <apex:pageblock >
            <apex:inputText value="{!Contact.AccountId}"/>
        </apex:pageblock>
        <apex:pageBlock >  
             <apex:pageBlockTable value="{!selected}" var="c">              
                <apex:column value="{!c.firstname}"/>
                <apex:column value="{!c.lastname}"/>     
                <apex:column value="{!c.Account.Name}"/>     
            </apex:pageBlockTable>           
        </apex:pageBlock>
    </apex:form>
</apex:page>
Best Answer chosen by Mallik Vemugunta
Arthur LockremArthur Lockrem
Please mark the response if your issue has been resolved.  Thank you

All Answers

Arthur LockremArthur Lockrem
Please help me understand what you mean by "the account page related list".  My related lists don't have an option to select contacts.  This may be the source of confustion or the issue.

The {!selected} value responds to the records selected on the previous page.  This is intended to be used when loading a Visualforce page from a List Button.

Note: I copied and pasted your 2nd page block into a Visualforce page, loaded it from a List Button, and it worked perfectly.

I will be happy to help however I can, but I'm not 100% sure my understanding of your goals are correct.  If you can provide more information I'll do my best to help you get this up and running.
Mallik VemuguntaMallik Vemugunta
Thank you, this what I did, I  created a new button Account Update button on contacts object (On  creation I chose last option list  Button)and assign  this visual force code, went to account page layout and from contact related list I added this  button .
I choose the account  that had 2 contacts and after selecting  the contacts I clicked the new Account Update button and I am not getting any data displayed.
Mallik VemuguntaMallik Vemugunta
Please se the screen shot of my selcted  conacts and new button in account related list.

User-added image
 
Arthur LockremArthur Lockrem
1. Thank you for teaching me that list buttons can be used in related lists.  I've never done that before.
2. Your code worked for me.  I did exactly what you mentioned, with your code, and it worked (except for the account id textbox).
<apex:page StandardController="Contact" recordSetVar="contacts">
    <apex:form >
        <apex:pageblock >
            <apex:inputText value="{!Contact.AccountId}"/>
        </apex:pageblock>
        <apex:pageBlock >  
             <apex:pageBlockTable value="{!selected}" var="c">              
                <apex:column value="{!c.firstname}"/>
                <apex:column value="{!c.lastname}"/>     
                <apex:column value="{!c.Account.Name}"/>     
            </apex:pageBlockTable>           
        </apex:pageBlock>
    </apex:form>
</apex:page>
Arthur LockremArthur Lockrem
One thing to note: I have the content source set to Visualforce Page.  That may cause an issue if yours is set manually.
User-added image
Mallik VemuguntaMallik Vemugunta
Thanks Arthur, I missed content source.
Arthur LockremArthur Lockrem
Please mark the response if your issue has been resolved.  Thank you
This was selected as the best answer