You need to sign in to do that
Don't have an account?

How to add my query to below pagenation code?
public pageReference doSearch()
{
System.debug('***dbPDF***'+dbPDF);
display=true;
String strQuery = 'SELECT Name, Accountnumber__c, Phone, Fax FROM Account ';
// Date onOrAfterDate = dbPDF.Instrument_Date__c;
// Date onOrBeforeDate = con.Birthdate;
if(dbPDF.name != null || dbPDF.Accountnumber__c != NULL || dbPDF.Phone != NULL || dbPDF.Fax != NULL){
strQuery += 'WHERE ';
}
if(dbPDF.Accountnumber__c != NULL){
strQuery += 'name =\'' + dbPDF.name + '\' AND ' ;
}
if(dbPDF.Accountnumber__c != NULL){
strQuery += 'Accountnumber__c =\'' + dbPDF.Accountnumber__c + '\' AND ' ;
}
if(dbPDF.Fax != NULL){
strQuery += 'Fax =\'' + dbPDF.Fax + '\' AND ' ;
}
if(dbPDF.Phone != NULL){
strQuery += 'Phone =\''+dbPDF.Phone+ '\'AND ';
}
strQuery = strQuery.substring(0, strQuery.length()-4);
System.debug('!!! '+strQuery);
records = Database.query(strQuery);
return null;
}
How to add above code in below controller code
Mypage:
--------
<apex:page controller="pagingControllerForUser1">
<apex:form >
<apex:pageBlock >
<apex:pageMessages id="pgm"/>
<apex:pageBlockButtons >
<apex:commandButton value="Search" action="{!Search}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection >
<apex:inputField value="{!dbPDF.name}"/>
<apex:inputField value="{!dbPDF.phone}"/>
<apex:inputField value="{!dbPDF.Fax}"/>
<apex:inputField value="{!dbPDF.Accountnumber__c}"/>
<!-- <apex:inputField value="{!con.Birthdate}" label="On or Before"/>-->
</apex:pageBlockSection>
</apex:pageBlock>
<apex:pageBlock rendered="{!IF(AllSearchUsers.size != null && AllSearchUsers.size > 0, true , false)}">
<apex:outputPanel layout="block" styleClass="pSearchShowMore" id="otpNav2">
Total Records Found: <apex:outputText rendered="{!IF(Con.resultSize==10000,true,false)}">10000 +</apex:outputText><apex:outputText rendered="{!IF(Con.resultSize < 10000,true,false)}">{!Con.resultSize}</apex:outputText>
<apex:image url="/img/search_prevarrow_disabled.gif" styleClass="prevArrow" rendered="{!NOT(Con.HasPrevious)}"/>
<apex:image url="/img/search_prevarrow.gif" title="Previous Page" styleClass="prevArrow" rendered="{!Con.HasPrevious}"/>
<apex:commandLink action="{!Previous}" title="Previous Page" value="Previous Page" rendered="{!Con.HasPrevious}"/>
<apex:outputPanel styleClass="pShowLess noLink" style="color:grey" rendered="{!NOT(Con.HasPrevious)}">Previous Page</apex:outputPanel>
({!IF(Con.PageNumber == 1,1,((Con.PageNumber -1) * Con.PageSize)+1)}-{!IF(Con.resultSize < Con.PageSize,Con.resultSize,Con.PageNumber * Con.pageSize)})
<apex:outputPanel styleClass="pShowLess noLink" style="color:grey" rendered="{!NOT(Con.HasNext)}">Next Page</apex:outputPanel>
<apex:commandLink title="Next Page" value="Next Page" rendered="{!Con.HasNext}" action="{!Next}"/>
<apex:image url="/img/search_nextarrow.gif" title="Next Page" styleClass="nextArrow" rendered="{!Con.HasNext}"/>
<apex:image url="/img/search_nextarrow_disabled.gif" rendered="{!NOT(Con.HasNext)}"/>
</apex:outputPanel>
<apex:pageBlockSection columns="1">
<apex:pageBlockTable var="UR" value="{!AllSearchUsers}" id="pbTable">
<apex:column value="{!UR.Name}" />
<apex:column headerValue="Accountnumber">
<apex:commandLink value="{!UR.Accountnumber__c}" action="{!displayFields}">
<apex:param name="RecordId Id" value="{!UR.Id}" assignTo="{!RecordId}"/>
</apex:commandlink>
</apex:column>
<apex:column value="{!UR.phone}" />
<apex:column value="{!UR.Fax}" />
</apex:pageBlockTable>
</apex:pageBlockSection>
<apex:outputPanel layout="block" styleClass="pSearchShowMore" id="otpNav">
Total Records Found: <apex:outputText rendered="{!IF(Con.resultSize==10000,true,false)}">10000 +</apex:outputText><apex:outputText rendered="{!IF(Con.resultSize < 10000,true,false)}">{!Con.resultSize}</apex:outputText>
<apex:image url="/img/search_prevarrow_disabled.gif" styleClass="prevArrow" rendered="{!NOT(Con.HasPrevious)}"/>
<apex:image url="/img/search_prevarrow.gif" title="Previous Page" styleClass="prevArrow" rendered="{!Con.HasPrevious}"/>
<apex:commandLink action="{!Previous}" title="Previous Page" value="Previous Page" rendered="{!Con.HasPrevious}"/>
<apex:outputPanel styleClass="pShowLess noLink" style="color:grey" rendered="{!NOT(Con.HasPrevious)}">Previous Page</apex:outputPanel>
({!IF(Con.PageNumber == 1,1,((Con.PageNumber -1) * Con.PageSize)+1)}-{!IF(Con.resultSize < Con.PageSize,Con.resultSize,Con.PageNumber * Con.pageSize)})
<apex:outputPanel styleClass="pShowLess noLink" style="color:grey" rendered="{!NOT(Con.HasNext)}">Next Page</apex:outputPanel>
<apex:commandLink title="Next Page" value="Next Page" rendered="{!Con.HasNext}" action="{!Next}"/>
<apex:image url="/img/search_nextarrow.gif" title="Next Page" styleClass="nextArrow" rendered="{!Con.HasNext}"/>
<apex:image url="/img/search_nextarrow_disabled.gif" rendered="{!NOT(Con.HasNext)}"/>
</apex:outputPanel>
</apex:pageBlock>
</apex:form>
</apex:page>
Example Controller:
--------------------------------
public class pagingControllerForUser
{
public List<Account> AllSearchUsers
{
get
{
if(con != null)
return (List<Account>)con.getRecords();
else
return null ;
}
set;}
public Account usr {get; set;}
//Controller
public pagingControllerForUser()
{
AllSearchUsers = new List<Account>() ;
usr = new Account() ;
}
public PageReference Search()
{
if(usr.Name != null)
{
con = new ApexPages.StandardSetController(Database.getQueryLocator([select Id , name , phone,Fax from Account where name = :usr.Name]));
// sets the number of records in each page set
con.setPageSize(25);
}
else
{
con = null;
}
return null ;
}
//Instantiate the StandardSetController
public ApexPages.StandardSetController con{get; set;}
//Boolean to check if there are more records after the present displaying records
public Boolean hasNext
{
get
{
return con.getHasNext();
}
set;
}
//Boolean to check if there are more records before the present displaying records
public Boolean hasPrevious
{
get
{
return con.getHasPrevious();
}
set;
}
//Page number of the current displaying records
public Integer pageNumber
{
get
{
return con.getPageNumber();
}
set;
}
//Returns the previous page of records
public void previous()
{
con.previous();
}
//Returns the next page of records
public void next()
{
con.next();
}
}
Note:In above page is my visualforce page controller i get from Google
How to add My doSearch() in above controller?
please help me.......
{
System.debug('***dbPDF***'+dbPDF);
display=true;
String strQuery = 'SELECT Name, Accountnumber__c, Phone, Fax FROM Account ';
// Date onOrAfterDate = dbPDF.Instrument_Date__c;
// Date onOrBeforeDate = con.Birthdate;
if(dbPDF.name != null || dbPDF.Accountnumber__c != NULL || dbPDF.Phone != NULL || dbPDF.Fax != NULL){
strQuery += 'WHERE ';
}
if(dbPDF.Accountnumber__c != NULL){
strQuery += 'name =\'' + dbPDF.name + '\' AND ' ;
}
if(dbPDF.Accountnumber__c != NULL){
strQuery += 'Accountnumber__c =\'' + dbPDF.Accountnumber__c + '\' AND ' ;
}
if(dbPDF.Fax != NULL){
strQuery += 'Fax =\'' + dbPDF.Fax + '\' AND ' ;
}
if(dbPDF.Phone != NULL){
strQuery += 'Phone =\''+dbPDF.Phone+ '\'AND ';
}
strQuery = strQuery.substring(0, strQuery.length()-4);
System.debug('!!! '+strQuery);
records = Database.query(strQuery);
return null;
}
How to add above code in below controller code
Mypage:
--------
<apex:page controller="pagingControllerForUser1">
<apex:form >
<apex:pageBlock >
<apex:pageMessages id="pgm"/>
<apex:pageBlockButtons >
<apex:commandButton value="Search" action="{!Search}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection >
<apex:inputField value="{!dbPDF.name}"/>
<apex:inputField value="{!dbPDF.phone}"/>
<apex:inputField value="{!dbPDF.Fax}"/>
<apex:inputField value="{!dbPDF.Accountnumber__c}"/>
<!-- <apex:inputField value="{!con.Birthdate}" label="On or Before"/>-->
</apex:pageBlockSection>
</apex:pageBlock>
<apex:pageBlock rendered="{!IF(AllSearchUsers.size != null && AllSearchUsers.size > 0, true , false)}">
<apex:outputPanel layout="block" styleClass="pSearchShowMore" id="otpNav2">
Total Records Found: <apex:outputText rendered="{!IF(Con.resultSize==10000,true,false)}">10000 +</apex:outputText><apex:outputText rendered="{!IF(Con.resultSize < 10000,true,false)}">{!Con.resultSize}</apex:outputText>
<apex:image url="/img/search_prevarrow_disabled.gif" styleClass="prevArrow" rendered="{!NOT(Con.HasPrevious)}"/>
<apex:image url="/img/search_prevarrow.gif" title="Previous Page" styleClass="prevArrow" rendered="{!Con.HasPrevious}"/>
<apex:commandLink action="{!Previous}" title="Previous Page" value="Previous Page" rendered="{!Con.HasPrevious}"/>
<apex:outputPanel styleClass="pShowLess noLink" style="color:grey" rendered="{!NOT(Con.HasPrevious)}">Previous Page</apex:outputPanel>
({!IF(Con.PageNumber == 1,1,((Con.PageNumber -1) * Con.PageSize)+1)}-{!IF(Con.resultSize < Con.PageSize,Con.resultSize,Con.PageNumber * Con.pageSize)})
<apex:outputPanel styleClass="pShowLess noLink" style="color:grey" rendered="{!NOT(Con.HasNext)}">Next Page</apex:outputPanel>
<apex:commandLink title="Next Page" value="Next Page" rendered="{!Con.HasNext}" action="{!Next}"/>
<apex:image url="/img/search_nextarrow.gif" title="Next Page" styleClass="nextArrow" rendered="{!Con.HasNext}"/>
<apex:image url="/img/search_nextarrow_disabled.gif" rendered="{!NOT(Con.HasNext)}"/>
</apex:outputPanel>
<apex:pageBlockSection columns="1">
<apex:pageBlockTable var="UR" value="{!AllSearchUsers}" id="pbTable">
<apex:column value="{!UR.Name}" />
<apex:column headerValue="Accountnumber">
<apex:commandLink value="{!UR.Accountnumber__c}" action="{!displayFields}">
<apex:param name="RecordId Id" value="{!UR.Id}" assignTo="{!RecordId}"/>
</apex:commandlink>
</apex:column>
<apex:column value="{!UR.phone}" />
<apex:column value="{!UR.Fax}" />
</apex:pageBlockTable>
</apex:pageBlockSection>
<apex:outputPanel layout="block" styleClass="pSearchShowMore" id="otpNav">
Total Records Found: <apex:outputText rendered="{!IF(Con.resultSize==10000,true,false)}">10000 +</apex:outputText><apex:outputText rendered="{!IF(Con.resultSize < 10000,true,false)}">{!Con.resultSize}</apex:outputText>
<apex:image url="/img/search_prevarrow_disabled.gif" styleClass="prevArrow" rendered="{!NOT(Con.HasPrevious)}"/>
<apex:image url="/img/search_prevarrow.gif" title="Previous Page" styleClass="prevArrow" rendered="{!Con.HasPrevious}"/>
<apex:commandLink action="{!Previous}" title="Previous Page" value="Previous Page" rendered="{!Con.HasPrevious}"/>
<apex:outputPanel styleClass="pShowLess noLink" style="color:grey" rendered="{!NOT(Con.HasPrevious)}">Previous Page</apex:outputPanel>
({!IF(Con.PageNumber == 1,1,((Con.PageNumber -1) * Con.PageSize)+1)}-{!IF(Con.resultSize < Con.PageSize,Con.resultSize,Con.PageNumber * Con.pageSize)})
<apex:outputPanel styleClass="pShowLess noLink" style="color:grey" rendered="{!NOT(Con.HasNext)}">Next Page</apex:outputPanel>
<apex:commandLink title="Next Page" value="Next Page" rendered="{!Con.HasNext}" action="{!Next}"/>
<apex:image url="/img/search_nextarrow.gif" title="Next Page" styleClass="nextArrow" rendered="{!Con.HasNext}"/>
<apex:image url="/img/search_nextarrow_disabled.gif" rendered="{!NOT(Con.HasNext)}"/>
</apex:outputPanel>
</apex:pageBlock>
</apex:form>
</apex:page>
Example Controller:
--------------------------------
public class pagingControllerForUser
{
public List<Account> AllSearchUsers
{
get
{
if(con != null)
return (List<Account>)con.getRecords();
else
return null ;
}
set;}
public Account usr {get; set;}
//Controller
public pagingControllerForUser()
{
AllSearchUsers = new List<Account>() ;
usr = new Account() ;
}
public PageReference Search()
{
if(usr.Name != null)
{
con = new ApexPages.StandardSetController(Database.getQueryLocator([select Id , name , phone,Fax from Account where name = :usr.Name]));
// sets the number of records in each page set
con.setPageSize(25);
}
else
{
con = null;
}
return null ;
}
//Instantiate the StandardSetController
public ApexPages.StandardSetController con{get; set;}
//Boolean to check if there are more records after the present displaying records
public Boolean hasNext
{
get
{
return con.getHasNext();
}
set;
}
//Boolean to check if there are more records before the present displaying records
public Boolean hasPrevious
{
get
{
return con.getHasPrevious();
}
set;
}
//Page number of the current displaying records
public Integer pageNumber
{
get
{
return con.getPageNumber();
}
set;
}
//Returns the previous page of records
public void previous()
{
con.previous();
}
//Returns the next page of records
public void next()
{
con.next();
}
}
Note:In above page is my visualforce page controller i get from Google
How to add My doSearch() in above controller?
please help me.......
Thank u .In my query small problem how to solve below Error
String strQuery = 'SELECT Field1__C,Field2__C,My_Date__C FROM object__c ';
Date onOrAfterDate = usr.My_Date__c;
Date onOrBeforeDate = contact.Birthdate;
if(usr.field1__c != NULL || usr.Field2__C != NULL || usr.My_Date__c != NULL){
strQuery += 'WHERE ';
}
if(usr.Instrument__c != NULL){
strQuery += 'Field1__c =\''+usr.Instrument__c +'\' AND';
}
if(My_Date__c!= NULL){
strQuery += 'My_Date__c <=:onOrBeforeDate AND';
}
if(onOrAfterDate != NULL){
strQuery += 'My_Date__c >=:onOrAfterDate AND';
}
strQuery = strQuery.substring(0, strQuery.length()-4);
System.debug('!!! '+strQuery);
con = new ApexPages.StandardSetController(Database.getQueryLocator(strQuery));
con.setPageSize(25);
I got following Error
-------------------------------
System.QueryException: unexpected token: 'ANDMy_Date__c'
Error is in expression '{!Search}' in component <apex:commandButton> in page rajesh:mysearchpage: Class.rajesh.MySearchpageController.search: line 90, column 1
Class.rajesh.MySearchpageController.search: line 90, column 1
Column 90:con = new ApexPages.StandardSetController(Database.getQueryLocator(strQuery));
please help me..........
For the String variable strQuery where you are appending AND, leave a blank space before closing quotes and also start the next string append with a blank space like this
strQuery += ' My_Date__c <=:onOrBeforeDate AND ';
Kindly mark this as the answer if you are resolved
Thanks