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
buggs sfdcbuggs sfdc 

pagination for the below class

HI,

Can any one help me out with the pagination on standardcontroller,here is my code,am getting below error.
Error: Unknown property 'ApexPages.StandardSetController.Name'
public with sharing class ShowRelatedSubscription {

  private final Account acct;
  public list<Zuora__Subscription__c> conLst{get;set;}
  public List<Zuora__SubscriptionProductCharge__c> subLst {get;set;}

    public ShowRelatedSubscription(ApexPages.StandardController controller) {
      //this.acct = (Account)Controller.getRecord();
   Zuora__Subscription__c zsub  = [select name, Zuora__InitialTerm__c,Zuora__RenewalTerm__c, Zuora__SubscriptionStartDate__c, Zuora__SubscriptionEndDate__c,Current_Term__c,(select name, Zuora__Type__c,Zuora__Price__c, Zuora__Quantity__c, Zuora__RatePlanName__c from Zuora__Subscription_Product_Charges__r) from Zuora__Subscription__c  where Zuora__Account__c = :ApexPages.currentPage().getParameters().get('id') AND Zuora__Status__c = 'Active'];
   // subLst = zsub.Zuora__Subscription__c;
    }     
    
     public ApexPages.StandardSetController con {
        get {
            if(con == null) {
                con = new ApexPages.StandardSetController(Database.getQueryLocator([select name, Zuora__InitialTerm__c,Zuora__RenewalTerm__c, Zuora__SubscriptionStartDate__c, Zuora__SubscriptionEndDate__c,Current_Term__c,(select name, Zuora__Type__c,Zuora__Price__c, Zuora__Quantity__c, Zuora__RatePlanName__c from Zuora__Subscription_Product_Charges__r) from Zuora__Subscription__c  where Zuora__Account__c = :ApexPages.currentPage().getParameters().get('id') AND Zuora__Status__c = 'Active']));
                // sets the number of records in each page set
                con.setPageSize(5);
            }
            return con;
        }
        set;
    }
   
         
     public List< Zuora__Subscription__c > zqu{
        get
        {
         // return [select id, Zuora__InitialTerm__c,Zuora__RenewalTerm__c, Zuora__SubscriptionStartDate__c, Zuora__SubscriptionEndDate__c,Current_Term__c from Zuora__Subscription__c WHERE Zuora__Account__c = :ApexPages.currentPage().getParameters().get('id') AND Zuora__Status__c = 'Active'];
       return [select name, Zuora__InitialTerm__c,Zuora__RenewalTerm__c, Zuora__SubscriptionStartDate__c, Zuora__SubscriptionEndDate__c,Current_Term__c,(select name, Zuora__Type__c,Zuora__Price__c, Zuora__Quantity__c, Zuora__RatePlanName__c from Zuora__Subscription_Product_Charges__r) from Zuora__Subscription__c where Zuora__Account__c = :ApexPages.currentPage().getParameters().get('id') AND Zuora__Status__c = 'Active'];
        
        }
        
      }  
     

    // returns the first page of records
     public void first() {
        con.first();
     }

     // returns the last page of records
       public void previous() {
         con.previous();
     }

    public void last() {
         con.last();
     }

      public void next() {
             con.next();
         }
 
 public Boolean hasNext {
        get {
            return con.getHasNext();
        }
        set;
    }

    // indicates whether there are more records before the current page set.
    public Boolean hasPrevious {
        get {
            return con.getHasPrevious();
        }
        set;
    }
 
 
  }
 
<apex:page standardController="Account" extensions="ShowRelatedSubscription" showChat="false"  label="width :1000px" >
 
    <apex:form >
    <div id="my-timeline" style="width:1100px; border: 1px solid #aaa">
       <apex:pageBlock >
         <apex:pageBlockSection >
           
       
           <apex:pageBlockTable value="{!zqu}" var="sub" width="10000%">
           <div id="my-timeline" style="width:1500px; border: 1px solid #aaa">
              <apex:column value="{!sub.Name}"/>
              <apex:column value="{!sub.Zuora__SubscriptionStartDate__c}"/>         
              <apex:column value="{!sub.Zuora__SubscriptionEndDate__c}"/> 
              <apex:column value="{!sub.Zuora__InitialTerm__c}"/>
              <apex:column value="{!sub.Current_Term__c}"/> 
              <apex:column value="{!sub.Zuora__RenewalTerm__c}"/>
                       </div>
           <apex:column headerValue="Subscription Product & Charge">
            <apex:pageBlockTable value="{!sub.Zuora__Subscription_Product_Charges__r}" var="con" width="10000%">
            <div id="my-timeline" style="width:1500px; border: 1px solid #aaa">
            <apex:column value="{!con.Name}"/>
            <apex:column value="{!con.Zuora__Type__c}"/>
            <apex:column value="{!con.Zuora__Price__c}"/>
              <apex:column value="{!con.Zuora__Quantity__c}"/>
              <apex:column value="{!con.Zuora__RatePlanName__c}"/> 
              </div>
              </apex:pageblockTable>
           
            </apex:column>
             
              
                </apex:pageblocktable>
           
         </apex:pageBlockSection>
 
       </apex:pageBlock>
          </div>
    
    <apex:panelGrid columns="4" cellpadding="5">
    <apex:commandLink action="{!first}">1</apex:commandlink>
    <apex:commandLink action="{!previous}" rendered="{!hasPrevious}">2</apex:commandlink>
    <apex:commandLink action="{!next}" rendered="{!hasNext}">3</apex:commandlink>
    <apex:commandLink action="{!last}">4</apex:commandlink>
    </apex:panelGrid>      
     

    </apex:form>
 
</apex:page>


 
PRABHAKARAN CHOCKALINGAMPRABHAKARAN CHOCKALINGAM
Plz try changing the variable name('con') in the below code as,
<apex:pageBlockTable value="{!sub.Zuora__Subscription_Product_Charges__r}"var="con" width="10000%">.
Below code worked,
<apex:page standardController="Account" extensions="ShowRelatedSubscription" showChat="false"  label="width :1000px" >

    <apex:form >
        <div id="my-timeline" style="width:1100px; border: 1px solid #aaa">
            <apex:pageBlock >
                <apex:pageBlockSection >


                    <apex:pageBlockTable value="{!Subscriptions}" var="sub" width="10000%">
                        <div id="my-timeline" style="width:1500px; border: 1px solid #aaa">
                            <apex:column value="{!sub.Name}"/>
                            <apex:column value="{!sub.SubscriptionStartDate__c}"/>
                            <apex:column value="{!sub.SubscriptionEndDate__c}"/>
                            <apex:column value="{!sub.InitialTerm__c}"/>
                            <apex:column value="{!sub.Current_Term__c}"/>
                            <apex:column value="{!sub.RenewalTerm__c}"/>
                        </div>
                        <apex:column headerValue="Subscription Product & Charge">
                            <apex:pageBlockTable value="{!sub.SubscriptionProductCharges__r}" var="con1" width="10000%">
                                <div id="my-timeline" style="width:1500px; border: 1px solid #aaa">
                                    <apex:column value="{!con1.Name}"/>
                                    <apex:column value="{!con1.Type__c}"/>
                                    <apex:column value="{!con1.Price__c}"/>
                                    <apex:column value="{!con1.Quantity__c}"/>
                                    <apex:column value="{!con1.RatePlanName__c}"/>
                                </div>
                            </apex:pageblockTable>

                        </apex:column>


                    </apex:pageblocktable>

                </apex:pageBlockSection>

            </apex:pageBlock>
        </div>

        <apex:panelGrid columns="4" cellpadding="5">
            <apex:commandLink action="{!con.first}">1</apex:commandlink>
            <apex:commandLink action="{!con.previous}" rendered="{!con.hasPrevious}">2</apex:commandlink>
            <apex:commandLink action="{!con.next}" rendered="{!con.hasNext}">3</apex:commandlink>
            <apex:commandLink action="{!con.last}">4</apex:commandlink>
        </apex:panelGrid>


    </apex:form>

</apex:page>



 
buggs sfdcbuggs sfdc
hey PRABHAKARAN CHOCKALINGAM,

can you please help me out to cover the test class for it am keep on getting an error as below;
 
Error: Compile Error: Constructor not defined: [ShowRelatedSubscription].<Constructor>(ApexPages.StandardSetController) at line 5 column 34


 
Amit Chaudhary 8Amit Chaudhary 8
Please post your apex class and test class which you are using.

You can check sample code on below post
1) http://amitsalesforce.blogspot.com/2015/06/best-practice-for-test-classes-sample.html
 
buggs sfdcbuggs sfdc

public class acccont {

public acccont(ApexPages.StandardController controller){}
public list<acccont> zsubLst{get;set;}
public ApexPages.StandardSetController cont {
get {
if(cont == null) {
cont = new ApexPages.StandardSetController(Database.getQueryLocator([select,id,name(Select id,Firstname from Contacts) From Account where Accountid = :ApexPages.currentPage().getParameters().get('id') AND Status__c = 'Active']));
}
return cont;
}
set;
}
public List< acccont > zqu{
get
{
cont.setPageSize(5);
return (List<acccont>) cont.getRecords();
}
}
// returns the first page of records
public void first() {
cont.first();
}
// returns the last page of records
public void previous() {
cont.previous();
}
public void last() {
cont.last();
}
public void next() {
cont.next();
}
public Boolean hasNext {
get {
return cont.getHasNext();
}
set;
}
// indicates whether there are more records before the current page set.
public Boolean hasPrevious {
get {
return cont.getHasPrevious();
}
set;
}

}
@isTest(seealldata = true)
private class acccontTest {
static testMethod void testsub(){
List<acccont> lst =[select,id,name(Select id,Firstname from Contacts) From Account where Accountid = :ApexPages.currentPage().getParameters().get('id') AND Status__c = 'Active']);
acccont sc = new acccont(new ApexPages.StandardSetController( lst ));
}
}
i keep on getting an error "Error: Compile Error: Constructor not defined: [acccont].<Constructor>(ApexPages.StandardSetController) at line 5 column 34"

 
Amit Chaudhary 8Amit Chaudhary 8
Please rename your apex class like below because account is standard object and you are reusing same name
public class acccontClass {

public acccontClass(ApexPages.StandardController controller){}
public list<acccont> zsubLst{get;set;}
public ApexPages.StandardSetController cont {
get {
if(cont == null) {
cont = new ApexPages.StandardSetController(Database.getQueryLocator([select,id,name(Select id,Firstname from Contacts) From Account where Accountid = :ApexPages.currentPage().getParameters().get('id') AND Status__c = 'Active']));
}
return cont;
}
set;
}
public List< acccont > zqu{
get
{
cont.setPageSize(5);
return (List<acccont>) cont.getRecords();
}
}
// returns the first page of records
public void first() {
cont.first();
}
// returns the last page of records
public void previous() {
cont.previous();
}
public void last() {
cont.last();
}
public void next() {
cont.next();
}
public Boolean hasNext {
get {
return cont.getHasNext();
}
set;
}
// indicates whether there are more records before the current page set.
public Boolean hasPrevious {
get {
return cont.getHasPrevious();
}
set;
}

}



then try below code
@isTest
private class acccontTest 
{
	static testMethod void testsub()
	{
		Account acc = new Account();
		acc.Name ='Test';
		acc.Status__c = 'Active';
		// Add all required field here
		insert acc;
		
		Contact cont = new Contact();
		cont.Accountid =acc.id;
		cont.LastName ='Test';
		cont.FirstName ='Test';
		// Add all required field here
		insert cont;
		
		ApexPages.currentPage().getParameters().put('id', String.valueOf(acc.Id));	
		
		ApexPages.StandardController sc = new ApexPages.StandardController(acc);
		AcccontClass obj = new AccountClass(sc);
		List<Account> lstAcc = obj.zqu();
		obj.first();
		obj.last();
		obj.next();
		
		
	}
}

Let us know if this will help you
buggs sfdcbuggs sfdc
hi,

am getting the below error,can i hardcode it??
System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, Account: id value of incorrect type: a0DV0000003BaJ7MAK: []

 
Amit Chaudhary 8Amit Chaudhary 8
Where you are doing hardcoding ? I hope you are using above code ?