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
bujjibujji 

Need Test Class

Hi Guys,

 

Need Test calss for the below class.

 

public class accountdisplylink
{
        public string err{get;set;}
        public String ContryName{get;set;}
        //public String SearchtextAlpha{get;set;}    
        public ApexPages.StandardSetController con{get; set;}
        public accountdisplylink()
        {
            ContryName = Apexpages.currentPage().getParameters().get('name');
        }
          public List<Account> searchResults
            {
                get
                {
                    if(con != null)
                        return (List<Account>)con.getRecords();
                    else
                        return null ;
                }
                set;
            }               
        public pagereference search()
            {     
                ContryName = Apexpages.currentPage().getParameters().get('name');
                if(ContryName != null &&  !ContryName.trim().equals('') )
                {
              
               err='';
                 string baseQuery = 'Select Id,Name,BillingCity,BillinState,BillingPostalCode,Type from Account ';
                 string finalQuery = baseQuery +'WHERE Territory =\''+ContryName+'\' AND Customer_Type__c = \'Permanent\' Order By Name ';
                 con = new ApexPages.StandardSetController(Database.getQueryLocator(finalQuery));
                 con.setPageSize(300);
                 }
         return null;
               }
          
           public void PREVIOUS()
            {
                 con.PREVIOUS();            
            }
            public void NEXT()
            {
                 con.next();
            }
            public Boolean hasNext
            {
            get
            {
            return con.getHasNext();
            }
            set;
            }           
            public Boolean hasPrevious
            {
            get
            {
            return con.getHasPrevious();
            }
            set;
            }
   
}

 

 

Thanks,

Bujji

asish1989asish1989

Try this

For your reference Territory is not stanard field ,so I have append __c to that field.

@isTest
public class TestTaskAfterInsertUpdate
{
  static testMethod void TestTaskAfterInsertUpdate()
  {  
      Account acc = new Account();
	  acc.Name = 'test';
	  acc.BillingCity = 'testBillingCity';
	  acc.BillinState = 'testBillinState';
	  acc.BillingPostalCode = 'testBillingPostalCode';
	  acc.Type = 'Type';
	  acc.Customer_Type__c = 'Permanent';
	  acc.Territory__c = 'test';
	  insert acc;
	  ApexPages.StandardSetController testcon;
	  Apexpages.currentPage().getParameters().put(name,'test');
	  Test.startTest();
	  accountdisplylink accd = new accountdisplylink();
	  
	  accd.search();
	  accd.PREVIOUS();
	  accd.NEXT();
	  //accd.getHasNext();
	  //accd.getHasPrevious();
	  Test.StopTest();
	  
	  
  }
  }

 

bujjibujji
In the Search Method, the below lines are not code covering.

string baseQuery = 'Select Id,Name,BillingCity,BillinState,BillingPostalCode,Type from Account ';
string finalQuery = baseQuery +'WHERE Territory =\''+ContryName+'\' AND Customer_Type__c = \'Permanent\' Order By Name ';
con = new ApexPages.StandardSetController(Database.getQueryLocator(finalQuery));
con.setPageSize(300);

Thanks,
Bujji
asish1989asish1989

tell me what is Territory ?

is it a custom field?

If it is custom field then append  "__c " in your controller method then run test.