Skip to main content
Robert Goldberg 님이 #Apex에 질문했습니다
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>
답변 4개
  1. 2017년 11월 2일 오후 8:43
    Hey Robert, 

    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
0/9000