function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Linda 98Linda 98 

Help needed on test class using standardsetcontroller--URGENT

Hi i am having dynamic search page.For pagination i am using set controller.

But unable to get it complied.Pls help..

My apex class:

Public class  searchpageController2 {
   Public string inputNametext{get;set;}
   Public string inputAccounttext{get;set;}
   Public String soql{get;set;}
   Public List<Customobejct__c> accList{get;set;}

   public ApexPages.StandardSetController setCon {
     get{
       if(setCon == null){
        string soql='';
        size = 100;
        }
        soql = 'select Name,Account__c,Status_Picklist__c,Createddate,Walmart_MultiStore_Contact__c,View_FAR_PDF__c,Contact__c,Status__c,Closed_Date__c from Customobject__c where Walmart_MultiStore_Contact__r.Name =\''+Usernames+'\' or contact__r.Name =\''+Usernames+'\'';                             
      }
        setCon = new ApexPages.StandardSetController(Database.getQueryLocator(soql));
        setCon.setPageSize(size);
        noOfRecords = setCon.getResultSize();
      }
        return setCon;
        }
        set;
    }
    
    Public List<Customobejct__c> getAccounts(){
        List<Customobejct__c> accList = new List<Customobject__c>();
        for(Custom object__c a : (List<Customobject__c>)setCon.getRecords())
            accList.add(a);
        return accList;
    }
    
    
     public pageReference refresh() {
     setCon = null;
     getAccounts();
     setCon.setPageNumber(1);
     return null;
    }
    
    public Boolean hasNext {
        get {
            return setCon.getHasNext();
        }
        set;
    }
    public Boolean hasPrevious {
        get {
            return setCon.getHasPrevious();
        }
        set;
    }
 
    public Integer pageNumber {
        get {
            return setCon.getPageNumber();
        }
        set;
    }
 
    public void first() {
        setCon.first();
    }
 
    public void last() {
        setCon.last();
    }
 
    public void previous() {
        setCon.previous();
    }
 
    public void next() {
        setCon.next();
    }
   
   Public void searchRecords(){
     soql = 'select Name,Account__c,Status_Picklist__c,Walmart_MultiStore_Contact__c,Contact__c from Customobject__c where ( Walmart_MultiStore_Contact__r.Name =\''+Usernames+'\' Or Contact__r.Name= \''+Usernames+'\')';
    }
    if(string.isnotBlank(inputAccounttext)){
    soql += ' and Account__r.Name like '+'\''+'%'+inputaccounttext+'%'+'\'';
    system.debug('*******soql'+soql);    
    }
    if (string.isnotBlank(inputnametext)){
    soql += ' and Name like '+'\''+'%'+inputnametext+'%'+'\'';
       }
    setcon=new ApexPages.StandardSetController(Database.getQueryLocator(soql));
    } 

}

please help..
James LoghryJames Loghry
Please post the actual error so that we can help you "urgently".
Michael VerhovskiMichael Verhovski
public ApexPages.StandardSetController setCon {
     get{
       if(setCon == null){
        string soql='';
        size = 100;
        }
        soql = 'select Name,Account__c,Status_Picklist__c,Createddate,Walmart_MultiStore_Contact__c,View_FAR_PDF__c,Contact__c,Status__c,Closed_Date__c from Customobject__c where Walmart_MultiStore_Contact__r.Name =\''+Usernames+'\' or contact__r.Name =\''+Usernames+'\'';                             
      }
        setCon = new ApexPages.StandardSetController(Database.getQueryLocator(soql));
        setCon.setPageSize(size);
        noOfRecords = setCon.getResultSize();
      }
        return setCon;
        }
        set;
    }
Check your setCon method. You have to many right curly brackets. 

Linda 98Linda 98
Thanks  all...Its fixed:)