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
eriktowneriktown 

Calling another page with information from the Contact standardController

Hello!

 

I am trying to figure out how to pass information from the Contact standardController to another page. Ideally what I would like to do is to be able to pass the contact's email address into an arbitrary Apex method when the user presses the appropriate "purchase" button. Is this possible, perhaps by extending the controller?

 

Thanks!

 

Code below:

<apex:page standardController="Contact" recordSetVar="contacts" tabStyle="Contact">
    <apex:form >
        <apex:pageBlock title="Purchase" mode="edit">
            <apex:pageMessages />
            <apex:pageBlockTable value="{!contacts}" var="contact">
                <apex:column value="{!contact.Name}"/>
                <apex:column headerValue="Email" value="{!contact.email}">
                </apex:column>
                <apex:column headerValue="Purchase">
                    <apex:commandButton value="Purchase"/>
                </apex:column>
            </apex:pageBlockTable>      
        </apex:pageBlock>
    </apex:form>
    </apex:page>

 

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

It is indeed possible and an extension controller would be the correct way to do this.  You can bind an action method (i.e. a method in your controller) to a command button via the 'action' attribute.

 

Take a look at the Visualforce Developer's Guide section on custom controllers and controller extensions at:

 

http://www.salesforce.com/us/developer/docs/pages/index_Left.htm#CSHID=pages_controller.htm|StartTopic=Content%2Fpages_controller.htm|SkinName=webhelp

 

This has examples of extension controllers and action methods.

 

 

 

 

All Answers

bob_buzzardbob_buzzard

It is indeed possible and an extension controller would be the correct way to do this.  You can bind an action method (i.e. a method in your controller) to a command button via the 'action' attribute.

 

Take a look at the Visualforce Developer's Guide section on custom controllers and controller extensions at:

 

http://www.salesforce.com/us/developer/docs/pages/index_Left.htm#CSHID=pages_controller.htm|StartTopic=Content%2Fpages_controller.htm|SkinName=webhelp

 

This has examples of extension controllers and action methods.

 

 

 

 

This was selected as the best answer
eriktowneriktown

Thanks! My only question then is, is it possible to pass the email address for that contact from the button to the custom method as a parameter? i'm not sure what the syntax would be; something like:

 

<apex:commandButton value="Purchase" action="{!purchase(contact.email)}"/>

 


 

bob_buzzardbob_buzzard

Ah - sorry, I didn't read your original post closely enough.

 

You can't pass a parameter back to the controller method, what you have to do is specify an apex:param that sets the email address into a property on the controller prior the executing the method.  While this sounds complex, it isn't, its just an odd concept to get your head around.

 

There's an example of passing information back to the controller in this way on a blog article of mine at:

 

http://bobbuzzard.blogspot.com/2011/03/edit-parent-and-child-records-with.html

 

This passes the id of the contact, but would be straightforward to change to the email address.