You need to sign in to do that
Don't have an account?
Robert Goldberg 9
How do I add a wrapper class (and buttons) to this controller?
I have a working Visualforce page and controller, that searches both Leads & Opportunities for a specific email address, and displays fields if there are any results.
I have been asked by our business department to make a change, adding checkboxes and radio buttons to the page.
I have no idea how I might begin doing this. Does anyone have any ideas?
Here is the controller:
Public with sharing class AllOppsearchClass{
Public List<Lead>leadList{get;set;}
Public List<Opportunity>optyList{get;set;}
Public String searchStr{get;set;}
Public AllOppsearchClass(){
}
public AllOppsearchClass(ApexPages.StandardController stdController){}
Public void soslDemo_method(){
leadList = New List<Lead>();
optyList = New List<Opportunity>();
if(searchStr.length() > 1){
String searchStr1 = '*'+searchStr+'*';
String searchQuery = 'FIND \'' + searchStr1 + '\' IN ALL FIELDS RETURNING Lead (Id,Name,Owner_Name__c,Email,metro__c,Last_Comment__c,statusname__c,Listing_MLS__c,last_update_date__c,date_entered_into_Lead_router__c,listing_amount__c,listing_agent__c,referral_fee__c,last_activity_subject__c),Opportunity(Id,Name,Account_Email__c,Opportunity_EMail__c,metro__c,Last_Comment__c,statusname__c,Owner_Name__c,last_update_date__c,date_entered_into_Lead_router__c,listing_amount__c,listing_agent__c,agent__c,referral_fee__c,last_activity_subject__c)';
List<List <sObject>> searchList = search.query(searchQuery);
leadList = ((List<Lead>)searchList[0]);
optyList = ((List<Opportunity>)searchList[1]);
if(leadList.size() == 0 && optyList.size() == 0){
apexPages.addmessage(new apexpages.message(apexpages.severity.Error, 'Sorry, no results returned with matching string..'));
return;
}
}
else{
apexPages.addmessage(new apexpages.message(apexpages.severity.Error, 'Please enter at least two characters..'));
return;
}
}
}
And the Visualforce page:
<apex:page standardcontroller="Lead" extensions="AllOppsearchClass">
<apex:form >
<apex:inputText value="{!searchStr}"/>
<apex:commandButton value="Search in Lead, Opportunity" action="{!soslDemo_method}" reRender="lead,error,oppt" status="actStatusId"/>
<apex:actionStatus id="actStatusId">
<apex:facet name="start" >
<img src="/img/loading.gif"/>
</apex:facet>
</apex:actionStatus>
</apex:form>
<apex:outputPanel title="" id="error">
<apex:pageMessages ></apex:pageMessages>
</apex:outputPanel>
<apex:pageBlock title="Opportunities" id="oppt">
<apex:pageblockTable value="{!optyList}" var="opty">
<apex:column headervalue="Name"><apex:outputLink value="/{!opty.ID}" target="_blank">{!opty.name}</apex:outputLink></apex:column>
<apex:column value="{!opty.Account_Email__c}"/>
<apex:column value="{!opty.Metro__c}"/>
<apex:column value="{!opty.Owner_Name__c}"/>
<apex:column value="{!opty.StatusName__c}"/>
<apex:column value="{!opty.Date_Entered_Into_Lead_Router__c}"/>
<apex:column value="{!opty.Last_Update_Date__c}"/>
<apex:column value="{!opty.Listing_Amount__c}"/>
<apex:column value="{!opty.Listing_Agent__c}"/>
<apex:column value="{!opty.Agent__c}"/>
<apex:column value="{!opty.Referral_Fee__c}"/>
<apex:column value="{!opty.Last_Comment__c}"/>
</apex:pageblockTable>
</apex:pageBlock>
<apex:pageBlock title="Leads" id="lead">
<apex:pageblockTable value="{!leadList }" var="lead">
<apex:column headervalue="Name"><apex:outputLink value="/{!lead.ID}" target="_blank">{!lead.name}</apex:outputLink></apex:column>
<apex:column value="{!lead.email}"/>
<apex:column value="{!lead.Metro__c}"/>
<apex:column value="{!lead.Owner_Name__c}"/>
<apex:column value="{!lead.StatusName__c}"/>
<apex:column value="{!lead.Date_Entered_Into_Lead_Router__c}"/>
<apex:column value="{!lead.Last_Update_Date__c}"/>
<apex:column value="{!lead.Listing_Amount__c}"/>
<apex:column value="{!lead.Listing_MLS__c}"/>
<apex:column value="{!lead.Listing_Agent__c}"/>
<apex:column value="{!lead.Referral_Fee__c}"/>
<apex:column value="{!lead.Last_Comment__c}"/>
</apex:pageblockTable>
</apex:pageBlock>
</apex:page>
I have been asked by our business department to make a change, adding checkboxes and radio buttons to the page.
I have no idea how I might begin doing this. Does anyone have any ideas?
Here is the controller:
Public with sharing class AllOppsearchClass{
Public List<Lead>leadList{get;set;}
Public List<Opportunity>optyList{get;set;}
Public String searchStr{get;set;}
Public AllOppsearchClass(){
}
public AllOppsearchClass(ApexPages.StandardController stdController){}
Public void soslDemo_method(){
leadList = New List<Lead>();
optyList = New List<Opportunity>();
if(searchStr.length() > 1){
String searchStr1 = '*'+searchStr+'*';
String searchQuery = 'FIND \'' + searchStr1 + '\' IN ALL FIELDS RETURNING Lead (Id,Name,Owner_Name__c,Email,metro__c,Last_Comment__c,statusname__c,Listing_MLS__c,last_update_date__c,date_entered_into_Lead_router__c,listing_amount__c,listing_agent__c,referral_fee__c,last_activity_subject__c),Opportunity(Id,Name,Account_Email__c,Opportunity_EMail__c,metro__c,Last_Comment__c,statusname__c,Owner_Name__c,last_update_date__c,date_entered_into_Lead_router__c,listing_amount__c,listing_agent__c,agent__c,referral_fee__c,last_activity_subject__c)';
List<List <sObject>> searchList = search.query(searchQuery);
leadList = ((List<Lead>)searchList[0]);
optyList = ((List<Opportunity>)searchList[1]);
if(leadList.size() == 0 && optyList.size() == 0){
apexPages.addmessage(new apexpages.message(apexpages.severity.Error, 'Sorry, no results returned with matching string..'));
return;
}
}
else{
apexPages.addmessage(new apexpages.message(apexpages.severity.Error, 'Please enter at least two characters..'));
return;
}
}
}
And the Visualforce page:
<apex:page standardcontroller="Lead" extensions="AllOppsearchClass">
<apex:form >
<apex:inputText value="{!searchStr}"/>
<apex:commandButton value="Search in Lead, Opportunity" action="{!soslDemo_method}" reRender="lead,error,oppt" status="actStatusId"/>
<apex:actionStatus id="actStatusId">
<apex:facet name="start" >
<img src="/img/loading.gif"/>
</apex:facet>
</apex:actionStatus>
</apex:form>
<apex:outputPanel title="" id="error">
<apex:pageMessages ></apex:pageMessages>
</apex:outputPanel>
<apex:pageBlock title="Opportunities" id="oppt">
<apex:pageblockTable value="{!optyList}" var="opty">
<apex:column headervalue="Name"><apex:outputLink value="/{!opty.ID}" target="_blank">{!opty.name}</apex:outputLink></apex:column>
<apex:column value="{!opty.Account_Email__c}"/>
<apex:column value="{!opty.Metro__c}"/>
<apex:column value="{!opty.Owner_Name__c}"/>
<apex:column value="{!opty.StatusName__c}"/>
<apex:column value="{!opty.Date_Entered_Into_Lead_Router__c}"/>
<apex:column value="{!opty.Last_Update_Date__c}"/>
<apex:column value="{!opty.Listing_Amount__c}"/>
<apex:column value="{!opty.Listing_Agent__c}"/>
<apex:column value="{!opty.Agent__c}"/>
<apex:column value="{!opty.Referral_Fee__c}"/>
<apex:column value="{!opty.Last_Comment__c}"/>
</apex:pageblockTable>
</apex:pageBlock>
<apex:pageBlock title="Leads" id="lead">
<apex:pageblockTable value="{!leadList }" var="lead">
<apex:column headervalue="Name"><apex:outputLink value="/{!lead.ID}" target="_blank">{!lead.name}</apex:outputLink></apex:column>
<apex:column value="{!lead.email}"/>
<apex:column value="{!lead.Metro__c}"/>
<apex:column value="{!lead.Owner_Name__c}"/>
<apex:column value="{!lead.StatusName__c}"/>
<apex:column value="{!lead.Date_Entered_Into_Lead_Router__c}"/>
<apex:column value="{!lead.Last_Update_Date__c}"/>
<apex:column value="{!lead.Listing_Amount__c}"/>
<apex:column value="{!lead.Listing_MLS__c}"/>
<apex:column value="{!lead.Listing_Agent__c}"/>
<apex:column value="{!lead.Referral_Fee__c}"/>
<apex:column value="{!lead.Last_Comment__c}"/>
</apex:pageblockTable>
</apex:pageBlock>
</apex:page>
Hi Robert!
I've taken a crack at what I think you need. It was a little hard to tell from your description, but I think what you were saying you need is to add checkbox options and radio select options to each row that is returned? (If this is information that needs to be saved, then instead of using a wrapper class, you will need to add them as fields on the objects, which you can then call as normal.)
I've commented in each place where I've added something your originals:
In the controller, what I've done is create a separate wrapper class for each object type, then filled a list of each using the results returned by your SOSL query. In the wrapper classes, I have a property for the main record that is being accessed, as well as Boolean properties for the checkbox fields and String properties for the radio select fields. I created two of each kind, but you can replicate for as many as you need. For the radio options, I created a list of SelectOption records for each field that you need (again, I created two, but you can replicate as many as needed).In the Visualforce page, I have just switched the data tables to use the wrapper lists instead of the direct lists that you have, and then added columns for each of the checkbox and radio select options.
Since I am not sure what the checkbox and radio select fields would be for, I didn't add any methods or anything using them, but you can then access those values from Apex methods as long as the page is loaded (because they are not actually saved to Lead or Opportunity records, they are not persistent values; see my comment at the beginning).
Let me know if that is helpful!
- Joe Brodar
I realized I did not update the Name column fields in either of the data tables. Instead of {!lead.ID} it should be {!lead.l.ID} and {!lead.l.Name}, etc because we need to call down the wrapper hierarchy. If you are getting a Visualforce error, that is probably why.
- Joe
Thanks so much for your updates - it took me a while to get through this, but I think I actually did a bad job of what I'm really looking for.
The Visualforce page should be a search. I want to be able to use the search function, and then be able to use checkboxes next to the results, and then click list action buttons to perform actions against those items I have checked, not radio buttons. Sorry about that - bad descriptor on my part. I can't seem to get the Visualforce page to work as you have it here - and I'm not sure why.
Thanks,
Robert
Hi Robert!
Thank you for the clarification, I think my ammended code below should allow you to do the following:
- Search for Leads & Opportunities
- Display a checkbox next to each result in the tables
- Select the checkboxes next to each record that you want to take action on
- Click a button above the table, which will complete an action for each record you selected
In the Apex class, I removed the portions that were about the radio options, and added a method for an action on each record type:Then in the VF page, I removed the extra columns for the radio options and the extra checkbox, as well as adding an example action button above each results table:
Let me know if that more accurately reflects what you are going for!
- Joe
- Joe
Thanks very much - I think it's almost there. The class looks good, and after I made a couple of cosmetic changes to the page, it is generating and giving me the ability to show the checkmarks, which is great! I did have to make the class the controller, dropping the StandardController of Lead - it wouldn't save otherwise.
The real issue is that I can't seem to actually generate the buttons - no matter what values I choose for those buttons, it's giving me an error. So, if they're blank, it saves, but otherwise, it won't.
Here's what I have now:
And, ideally, I'd like to add buttons that are:
"Closed - Trash" (Closed_Trash)
"Closed - Cold" (Closed_Cold)
"Update Lead Router Comments" (Update_Lead_Router_Comments)
To both Opportunities & Leads.