• ashish.kumar171.3969654430835393E12
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Hi All,

My requirment is suppose i have contact,account,lead,oppertunity  object in vf i have one text box and one scarch button if am giveing any text and clicking on search button it shoud search that text on contact,account,lead,oppertunity objects and display data. i know how to do it on ome object like Lead how to implement on multiple objects using apex and vf page .

below is my code for single object search functionality :


vf page
------------------------------------------------------------------------------------
<apex:page controller="Leadpage2">
   <apex:form >
   <apex:pageMessage severity="error" strength="2"  summary="Error:" detail="{!errorMessage}"  rendered="{!errorMessage != null}"/>
   <table>
   <tr>
   <td>Lead: </td>
   <td><apex:inputtext value="{!name}" required="true"/></td>
   <td></td>
   <td><apex:commandButton action="{!search}" value="Go"/>
   </td>
   </tr>
   </table>
   <apex:pageBlock rendered="{!name != null}" >
   <apex:pageBlockSection title="Lead Details" rendered="{!errorMessage == null}">
   <apex:pageBlockTable value="{!records}" var="rec">
   <apex:column value="{!rec.Name}" headerValue="Name"/>
   <apex:column value="{!rec.Email}" headerValue="Email"/>
   <apex:column value="{!rec.Company}" headerValue="Company"/>
   </apex:pageBlockTable>
   </apex:pageBlockSection>
   </apex:pageBlock>
   </apex:form>
</apex:page>
----------------------------------------------------------------------------------------------------------
apex page
---------------------------------------------------------------------------------------
public class Leadpage2 {
public String name{ get ; set;}
List<Lead> records;
List<Lead> templi;
public String msg {get; set; }
public transient String errorMessage { get; set; }
String s { get; set; } 
    public List<Lead> getrecords(){
      return records;
      }
      public Leadpage2(){
       records = new List<Lead>();
    }
    public PageReference search() {
      s = '%' + name + '%';
       if(name.length()==0){
          errorMessage = 'Please enter a Lead Name';
         }
      records  =[select Name,Email,Company from Lead  where name like:s OR Email like:s OR Company like:s ];
       if(records !=null && records.size() ==0){
           errorMessage = 'LEAD NOT fOUND !';
         }
     return null;
   }
}

-----------------------------------------------------

any ideas appreciated........

Thanks,

Hareesh Goud N
  • April 08, 2014
  • Like
  • 0