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
HepnHepn 

Adding a customer button to a visualforce page

I'm new to visualforce development and I'm trying to add a custom button to a visualforce page that performs basic lead search functionality. I have the page up and running fine, but now I want to add a button that associates the found lead records to a campaign. So something like, Add to Campaign, button would be great. I know that custom controller needs to be built for the campaign button. Does anyone have any examples that might help with this scenario? 

 

Here's my existing code 

 

 <apex:page controller="theController" showHeader="false" standardStylesheets="false">

   <apex:form >      <apex:pageBlock mode="edit" id="block">         <apex:pageBlockSection >            <apex:pageBlockSectionItem >               <apex:outputLabel for="searchText">Search Text</apex:outputLabel>               <apex:panelGroup >                  <apex:inputText id="searchText" value="{!searchText}"/>                  <apex:commandButton value="Go!" action="{!doSearch}"                                       rerender="block" status="status"/>               </apex:panelGroup>            </apex:pageBlockSectionItem>        </apex:pageBlockSection>        <apex:actionStatus id="status" startText="requesting..."/>        <apex:pageBlockSection title="Results" id="results" columns="1">           <apex:pageBlockTable value="{!results}" var="l"                                rendered="{!NOT(ISNULL(results))}">              <apex:column value="{!l.name}"/>                            <apex:column value="{!l.phone}"/>                            <apex:column value="{!l.email}"/>                <apex:column value="{!l.description}"/>                 </apex:pageBlockTable>        </apex:pageBlockSection>      </apex:pageBlock>   </apex:form></apex:page>
bob_buzzardbob_buzzard

You would add a commandButton to a VF page that executes an action method (a method in your controller), so you shouldn't need to create a new controller unless you want to go to a new page and allow the user to manipulate the data some more.

 

The leads that have been returned are available in the results property of your controller, so you should be able to use them as-is.