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 the code on VF page
<apex:pageBlock title="Contact and Lead Search">
<h2 class="maintitle">Enter Search </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) ;
}
}
}