0

i am new on salesforce and trying to fetch out some data on my VF Page from lead and contacts in a date range. Now the problem i am getting is to group data between Contact and Lead.

This is hwo i want to show data

this is how i want to show data

this is the code on VF page

<apex:pageBlock title="Contact and Lead Search">
  <h2 class="maintitle">Enter Search &nbsp;&nbsp;</h2>
  Start date <apex:inputText styleClass="searchBox1" id="searchBox1" value="{!searchValue1}" />
  End date <apex:inputText styleClass="searchBox2" id="searchBox2" value="{!searchValue2}" />
  <apex:commandButton id="submit" value="Search" action="{!searchContacts}" />
</apex:pageBlock>
<apex:pageBlock title="Search Results">
  <apex:pageBlockTable value="{!searchResults}" var="c">
    <apex:column value="{!c.Name}" />
    <apex:column value="{!c.Phone}" />
    <apex:column value="{!c.Email}" />        
    <apex:column value="{!c.CreatedDate}"/>
  </apex:pageBlockTable>
  <apex:outputText value="{!msg}"></apex:outputText> 
  <apex:outputText value="{!msg1}"></apex:outputText> 

jQuery.noConflict();

 jQuery(document).ready(function() {
 jQuery('.searchBox1').datepicker({
     changeMonth: true,
     changeYear: true,
     dateFormat:"yy-mm-dd",
     showAnim: "fadeIn"
     })
  jQuery('.searchBox2').datepicker({
      changeMonth: true,
      changeYear: true,
      dateFormat:"yy-mm-dd",
      showAnim: "fadeIn"
     })
  });
</script>

and this is the conroller

public class Contact_Searcher_testing{ // Since we are creating an extension to the account standard controller, // create an account object to hold the current account Account a; public String searchValue1{get;set;} public String searchValue2{get;set;} public String obj1{get;set;} public String obj2{get;set;} public String msg{get;set;} public String msg1{get;set;}

public Contact_Searcher_testing(ApexPages.StandardController controller)
{
    // Get the current account, and store it in the account object
    a = (Account) controller.getRecord();
}

public List<Contact> searchResults
{    
    get{
        if(searchResults == null)
            searchResults = new List<Contact>();
        return searchResults;
    }
    set;
}  

 public List<Lead> searchResults1
{    
    get{
        if(searchResults1 == null)
            searchResults1 = new List<Lead>();
        return searchResults1;
    }
    set;
}





// No need to return the result set. We will just assign to the class variable
public void searchContacts()
{
   try{
    // Output the search value for debugging 
    Date beginDate = date.valueOf(searchValue1);
    Date endDate   = date.valueOf(searchValue2);
    //Date target_date = date.valueOf('2014-04-01 00:00:00');   
    //msg ='Message detail----'+searchValue1+'--'+searchValue2;       
    //msg1 ='Message detail----'+beginDate+'--'+endDate+'--'+target_date;
    msg1 ='Message detail----'+beginDate+'--'+endDate;
    msg ='';  
    //msg1 ='';

    List<Contact> contacts = new List<contact>();
    List<Lead> leads= new List<Lead>();

    // It gets a list of contacts under that account with filter dates.                
    contacts = [Select Id, Name, Email, Phone, CreatedDate from Contact WHERE CreatedDate >= :beginDate and CreatedDate <= :endDate ORDER BY CreatedDate DESC];

    leads= [Select Id, Name, Company, Email from Lead WHERE CreatedDate >= :beginDate and CreatedDate <= :endDate ORDER BY CreatedDate DESC];  



    searchResults = contacts;
    searchResults1 =leads;





    }
    catch(Exception e) 
    {
       ApexPages.addMessages(e) ; 
    }
}

}

2
  • It may be helpfull if you also post the visualforce code of this page. You can do this by updating your question. Apr 28, 2014 at 9:59
  • Please some one help
    – Abeey007
    May 1, 2014 at 14:45

1 Answer 1

0

</head>

<apex:pageBlock title="Contact and Lead Search">
  <h2 class="maintitle">Enter Search &nbsp;&nbsp;</h2>
  From Created Date: <apex:inputText styleClass="searchBox1" id="searchBox1" value="{!searchValue1}" />
  To Created Date: <apex:inputText styleClass="searchBox2" id="searchBox2" value="{!searchValue2}" />
     <apex:commandButton action="{!generate_data}" value="Fetch Data"/>   
     <apex:commandButton action="{!cancel_data}" value="Clear List"/>       
</apex:pageBlock>

<apex:pageBlock >
   <div style="border-bottom:1px solid #dbdbdb">
    <span style="font-size:12px; font-weight:bold;">{!msg}</span>
    <span style="padding-left:70px; font-size:12px; font-weight:bold;">{!msg1}</span>
    </div> 
   <table border="0" style="width:100%">  
       <tr class="headerRow">  
        <td><b>Domain</b></td><td><b>Full Name</b></td><td><b>Company</b></td><td><b>Status</b></td><td><b>Created Date</b></td><td><b>Type</b></td><td><b>Email</b></td></tr>  
      <apex:repeat value="{!disp_list}" var="ttt">  
          <tr>
              <td>{!ttt.accountName}</td>
              <td>{!ttt.contactName}<br/>{!ttt.leadName}</td>
              <td>{!ttt.contactAccount}<br/>{!ttt.leadCompany}</td>  
              <td>{!ttt.contactStatus}<br/>{!ttt.leadStatus}</td>
              <td>
                   <apex:outputText value="{0,date,dd/MM/yyyy}">
                      <apex:param value="{!ttt.contactCreatedDate}"/>
                      <apex:param value="{!ttt.leadCreatedDate}"/>
                   </apex:outputText><br/>
                    <apex:outputText value="{0,date,dd/MM/yyyy}">
                      <apex:param value="{!ttt.leadCreatedDate}"/>
                   </apex:outputText>
              </td>

              <td>{!ttt.contactType}<br/>{!ttt.leadType}</td> 
              <td>{!ttt.contactEmail}<br/>{!ttt.leadEmail}</td> 
         </tr>  
     </apex:repeat>  
  </table>  


 <script type="text/javascript">
 jQuery.noConflict();

 jQuery(document).ready(function() {
 jQuery('.searchBox1').datepicker({
     changeMonth: true,
     changeYear: true,
     dateFormat:"yy-mm-dd",
     showAnim: "fadeIn"
     })
  jQuery('.searchBox2').datepicker({
      changeMonth: true,
      changeYear: true,
      dateFormat:"yy-mm-dd",
      showAnim: "fadeIn"
     })
  });
    </script>

public class sun_example {

 //main class datatypes
  public String searchValue1{get;set;}
  public String searchValue2{get;set;}
  public String msg{get;set;}
  public String msg1{get;set;}
  public list<wrapperclass> disp_list{get;set;}  

//Declare a wrapper class  
public class wrapperclass{  

 //custom wrapper datatype  
  public string accountName{get;set;}
  public string accountCreatedDate{get;set;}
  public string domainName{get;set;}

  public string contactName{get;set;}
  public string contactEmail{get;set;}  
  public string contactPhone{get;set;}  
  public Date contactCreatedDate {get;set;}  
  public string contactAccount{get;set;}
  public string contactStatus{get;set;}
  public string contactType{get;set;}  

  public string leadName{get;set;}
  public string leadCompany{get;set;}
  public string leadEmail{get;set;}
  public Date leadCreatedDate{get;set;}
  public string leadPhone{get;set;} 
  public string leadStatus{get;set;}
  public string leadType{get;set;}   
}   

//constructor of main class
public sun_example(){  
 //define constructor to instantiate the wrapper data type  
       disp_list=new List<wrapperclass>();  
   }  

//Method for processing logic
public void generate_data(){

disp_list.clear();
Date beginDate = date.valueOf(searchValue1);
Date endDate   = date.valueOf(searchValue2); 

msg ='From Created Date: '+searchValue1; 
msg1 ='To Created Date: '+searchValue2;  

//query to fetch accounts data
Listacc =[select id,Name from account where createddate!=null order by name];

//Iterate through each list to extract the values and add it to the custom wrapper data type
for(integer p=0;p

         disp_list.add(ac); //add account to the list  

         List<contact>con=[Select Id, Name, Email, Phone, Account.Name, CreatedDate from Contact WHERE CreatedDate >= :beginDate and CreatedDate <= :endDate and Account.Name LIKE :('%'+acc[p].name+'%') ORDER BY CreatedDate DESC ];  
         for(integer i=0;i<con.size();i++){  
           wrapperclass qw=new wrapperclass();   //Instantiating the wrapper SObject   
           qw.contactName=con[i].name;
           qw.contactEmail=con[i].email;
           qw.contactAccount=con[i].Account.Name;
           qw.contactPhone=con[i].phone;
           qw.contactCreatedDate = date.valueOf(con[i].CreatedDate);
           qw.contactStatus='--';
           qw.contactType='Contact';

           disp_list.add(qw);  //add contacts to the list

        }

        List<lead>proList= [Select Id, Name,Phone,Company, Email,CreatedDate,Status from Lead WHERE CreatedDate >= :beginDate and CreatedDate <= :endDate and Company LIKE :('%'+acc[p].name+'%') ORDER BY CreatedDate DESC ];

         for(integer k=0;k<proList.size();k++){  
            wrapperclass w=new wrapperclass();  //Instantiating the wrapper SObject   

           w.leadName=proList[k].name; 
           w.leadCompany= proList[k].company;
           w.leadEmail= proList[k].email;
           w.leadCreatedDate= date.valueOf(proList[k].createddate);
           w.leadPhone= proList[k].phone;
           w.leadStatus= proList[k].status;
           w.leadType='Lead';

           disp_list.add(w);  //adding leads to the list  

     }  

  }

}

} public void cancel_data(){
disp_list.clear();
}
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .