0
Apex:page showheader="false" controller="Consent_Records_Ctrls" doctype="html-5.0" tabStyle="case">
      <apex:form >
      <apex:pageBlock title="Redelivery Report " >
      <apex:pageBlockSection title="Consent Records" >
      <apex:input type="date" value="{!startDate}" label="From Date">
     <!-- <apex:actionSupport event="onchange" action="{!ConsentDisplay}" reRender="abc">
</apex:actionSupport>-->
</apex:input>
<apex:input type="date" value="{!EndDate}" label="To Date">
<!--<apex:actionSupport event="onchange" action="{!ConsentDisplay}" reRender="abc">
</apex:actionSupport>-->
</apex:input>
                        <apex:commandButton value="Filter" action="{!consentFilter}" />
      </apex:pageBlockSection>
      <apex:pageBlockSection title="All Consent Records" >


      <apex:pageBlockTable value="{!allCon}" var="con" >
    <!--<Apex:column value="{!con.Account__r.Id}" headerValue="Account Id"/>-->
    <apex:column value="{!con.coutOfid}" headerValue="Eerdere Aanvragen TL"/>
    <Apex:column value="{!con.accid}" headerValue="AccountId"/>
    <Apex:column value="{!con.Name}" headerValue="Aanvrag"/>
    <apex:column value="{!con.Salutation}" headerValue="Aanhef"/>
    <apex:column value="{!con.FirstName}" headerValue="Voornam"/>
    <apex:column value="{!con.Initials}" headerValue="Initilen"/>
    <apex:column value="{!con.LastNamePrefix}" headerValue="Voorvoegsel"/>
    <apex:column value="{!con.LastName}" headerValue="Achternaam"/>
    <apex:column value="{!con.ElectricityCurrentRedeliveryNum}" headerValue="TL"/>
    <apex:column value="{!con.ElectricityCurrentRedeliveryLowNum}" headerValue="TL(laag)"/>
    <apex:column value="{!con.MeterTariffChoice}" headerValue="Meter"/>
    <apex:column value="{!con.PhoneNumber}" headerValue="Telefoon"/>
    <apex:column value="{!con.EmailAddress}" headerValue="Email"/>
    <apex:column value="{!con.Main_Street}" headerValue="Straat"/>
    <apex:column value="{!con.Main_Number}" headerValue="Huisnr."/>
    <!--<apex:column value="{!con.Main_Addition__c}" headerValue="Toev."/>-->
    <apex:column value="{!con.Main_PostalCode}" headerValue="Postcode"/>
    <apex:column value="{!con.Main_City}" headerValue="Plaatsnaam"/>
    <apex:column value="{!con.Exclude_from_Surveys}" headerValue="Geen enquetes"/> 
    <apex:column value="{!con.accid}" headerValue="Oudste TL-aanvraag Id"/> 
    <apex:column value="{!con.Name}" headerValue="Oudste TL-aanvraag"/> 
    <apex:column value="{!con.ElectricityCurrentRedeliveryNum}" headerValue="TL oud"/> 
    <apex:column value="{!con.ElectricityCurrentRedeliveryLowNum}" headerValue="TL oud (laag)"/> 
     </apex:pageBlockTable>


      </apex:pageBlockSection>

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

Controller Code :

public class Consent_Records_Ctrls {
public date startDate{get;set;}
public date EndDate{get;set;}
public  long store{get;set;}
public List<WrapConsent> allCon{get;set;}
public List<Consent__c> allConRecs{get;set;}
public map<string,string>MapAccAr=new map<string,string>();
public PageReference consentFilter() {


    for (AggregateResult groupedResults: [SELECT  Count(Id)ids,Account__r.Id accids FROM Consent__c where CreatedDate >=:startDate AND LastModifiedDate <=:EndDate GROUP BY Account__r.Id]) {
       // System.debug('ID' + ar.get('ids'));
       // System.debug('Count Id' + ar.get('expr0'));
              MapAccAr.put(string.valueof(groupedResults.get('accids')),string.valueof(groupedResults.get('ids')));
    }
    for(Consent__C consent:[select account__r.id,name,Salutation__c,FirstName__c ,Initials__c,LastNamePrefix__c,LastName__c,
            ElectricityCurrentRedeliveryNum__c,ElectricityCurrentRedeliveryLowNum__c ,MeterTariffChoice__c,
            PhoneNumber__C,EmailAddress__c,Main_Street__c,Main_Number__c,Main_Addition__c,Main_PostalCode__c,
            Main_City__c,Exclude_from_Surveys__c from Consent__c where CreatedDate >=:startDate AND CreatedDate<=:EndDate and 
            ElectricityCurrentRedeliveryNum__c > 0  and Status__c = 'Processed']){
               WrapConsent wrapCon=new WrapConsent();
               if(MapAccAr.containsKey(string.valueof(consent.account__r.id)))
               wrapCon.coutOfid=MapAccAr.get(string.valueof(consent.account__r.id));
               wrapCon.accid=string.valueof(consent.account__r.id);
               wrapCon.name=consent.name;
               wrapCon.Salutation=consent.Salutation__c;
               wrapCon.FirstName=consent.FirstName__c;
               wrapCon.Initials=consent.Initials__c;
               wrapCon.LastNamePrefix=consent.LastNamePrefix__c;
               wrapCon.LastName=consent.LastName__c;
               wrapCon.ElectricityCurrentRedeliveryNum=string.valueof(consent.ElectricityCurrentRedeliveryNum__c);
               wrapCon.ElectricityCurrentRedeliveryLowNum=string.valueof(consent.ElectricityCurrentRedeliveryLowNum__c);
               wrapCon.MeterTariffChoice=consent.MeterTariffChoice__c;
               wrapCon.PhoneNumber=string.valueof(consent.PhoneNumber__C);
               wrapCon.EmailAddress=consent.EmailAddress__c;
               wrapCon.Main_Street=consent.Main_Street__c;
               wrapCon.Main_Street=consent.Main_addition__c;
               wrapCon.Main_Number=string.valueof(consent.Main_Number__c);
               wrapCon.Main_PostalCode=consent.Main_PostalCode__c;
               wrapCon.Main_City=consent.Main_City__c;
               wrapCon.Exclude_from_Surveys=string.valueof(consent.Exclude_from_Surveys__c);

                }

            return null;
            return consentFilter();
        }
        public List<WrapConsent> getConsentlist() {
        return allCon;
        }

    public void ConsentDisplay()
        {
            if(startDate!=NULL&&EndDate!=NULL)
            {
                if(startDate!=NULL&&EndDate!=NULL)
                {              
                    store=1;
                }
                else
                {
                    store=0;
                }
            }

        }
        public class WrapConsent{
        public string coutOfid{set;get;}
        public string accid{set;get;}
        public string name{set;get;}
        public string Salutation{set;get;}
        public string FirstName{set;get;}
        public string Initials{set;get;}
        public string LastNamePrefix{set;get;}
        public string LastName{set;get;}
        public string ElectricityCurrentRedeliveryNum{set;get;}
        public string ElectricityCurrentRedeliveryLowNum{set;get;}
        public string MeterTariffChoice{set;get;}
        public string PhoneNumber{set;get;}
        public string EmailAddress{set;get;}
        public string Main_Street{set;get;}
        public string Main_Number{set;get;}
        public string Main_PostalCode{set;get;}
        public string Main_City{set;get;}
        public string Exclude_from_Surveys{set;get;}
        public string Main_addition{set;get;}

    }


    }
2

2 Answers 2

0

Looks like your struggling more with question .I have reedited your whole visualForce Page and Apex Controller. Check it is working for you. If your struggling run the code with step by step.

Visualforce Page :

<apex:page showheader="false" controller="Consent_Records_Ctrls" doctype="html-5.0" tabStyle="case">
    <apex:form >
        <apex:pageBlock title="Redelivery Report"  >
            <apex:pageBlockSection title="Consent Records" >
                <apex:input type="date" value="{!startDate}" label="From Date"></apex:input>
                <apex:input type="date" value="{!EndDate}" label="To Date"> </apex:input>            
                <apex:commandButton value="Filter" action="{!generateConsentlist}" reRender="RenderSectionId"/>
            </apex:pageBlockSection>
            <apex:pageBlockSection title="All Consent Records" id="RenderSectionId"> 
                <apex:pageBlockTable value="{!allCon}" var="con" >
                    <apex:column value="{!con.coutOfid}" headerValue="Eerdere Aanvragen TL"/>
                    <Apex:column value="{!con.accid}" headerValue="AccountId"/>
                    <Apex:column value="{!con.Name}" headerValue="Aanvrag"/>
                    <apex:column value="{!con.Salutation}" headerValue="Aanhef"/>
                    <apex:column value="{!con.FirstName}" headerValue="Voornam"/>
                    <apex:column value="{!con.Initials}" headerValue="Initilen"/>
                    <apex:column value="{!con.LastNamePrefix}" headerValue="Voorvoegsel"/>
                    <apex:column value="{!con.LastName}" headerValue="Achternaam"/>
                    <apex:column value="{!con.ElectricityCurrentRedeliveryNum}" headerValue="TL"/>
                    <apex:column value="{!con.ElectricityCurrentRedeliveryLowNum}" headerValue="TL(laag)"/>
                    <apex:column value="{!con.MeterTariffChoice}" headerValue="Meter"/>
                    <apex:column value="{!con.PhoneNumber}" headerValue="Telefoon"/>
                    <apex:column value="{!con.EmailAddress}" headerValue="Email"/>
                    <apex:column value="{!con.Main_Street}" headerValue="Straat"/>
                    <apex:column value="{!con.Main_Number}" headerValue="Huisnr."/>
                    <apex:column value="{!con.Main_PostalCode}" headerValue="Postcode"/>
                    <apex:column value="{!con.Main_City}" headerValue="Plaatsnaam"/>
                    <apex:column value="{!con.Exclude_from_Surveys}" headerValue="Geen enquetes"/> 
                    <apex:column value="{!con.accid}" headerValue="Oudste TL-aanvraag Id"/> 
                    <apex:column value="{!con.Name}" headerValue="Oudste TL-aanvraag"/> 
                    <apex:column value="{!con.ElectricityCurrentRedeliveryNum}" headerValue="TL oud"/> 
                    <apex:column value="{!con.ElectricityCurrentRedeliveryLowNum}" headerValue="TL oud (laag)"/> 
                </apex:pageBlockTable>    
            </apex:pageBlockSection>        
        </apex:pageBlock>
    </apex:form>
</apex:page>

Controller :

  public class Consent_Records_Ctrls {
        public date startDate{get;set;}
        public date EndDate{get;set;}
       // public  long store{get;set;}
        public List<WrapConsent> allCon{get;set;}
       // public List<Consent__c> allConRecs{get;set;}
        public map<string,string>MapAccAr=new map<string,string>();

        public Consent_Records_Ctrls() {
            allCon=new List<WrapConsent>();
        }
        public void consentFilter() { 
            allCon.clear();

            for (AggregateResult groupedResults: [SELECT  Count(Id)ids,Account__r.Id accids FROM Consent__c where CreatedDate >=:startDate AND LastModifiedDate <=:EndDate GROUP BY Account__r.Id])
                MapAccAr.put(string.valueof(groupedResults.get('accids')),string.valueof(groupedResults.get('ids')));

            for(Consent__C consent:[select account__r.id,name,Salutation__c,FirstName__c ,Initials__c,LastNamePrefix__c,LastName__c,
                                    ElectricityCurrentRedeliveryNum__c,ElectricityCurrentRedeliveryLowNum__c ,MeterTariffChoice__c,
                                    PhoneNumber__C,EmailAddress__c,Main_Street__c,Main_Number__c,Main_Addition__c,Main_PostalCode__c,
                                    Main_City__c,Exclude_from_Surveys__c from Consent__c where CreatedDate >=:startDate AND CreatedDate<=:EndDate and 
                                    ElectricityCurrentRedeliveryNum__c > 0  and Status__c = 'Processed']){
                                        WrapConsent wrapCon=new WrapConsent();
                                        if(MapAccAr.containsKey(string.valueof(consent.account__r.id)))
                                            wrapCon.coutOfid=MapAccAr.get(string.valueof(consent.account__r.id));
                                          else
                                            wrapCon.coutOfid='1';
                                        wrapCon.accid=string.valueof(consent.account__r.id);
                                        wrapCon.name=consent.name;
                                        wrapCon.Salutation=consent.Salutation__c;
                                        wrapCon.FirstName=consent.FirstName__c;
                                        wrapCon.Initials=consent.Initials__c;
                                        wrapCon.LastNamePrefix=consent.LastNamePrefix__c;
                                        wrapCon.LastName=consent.LastName__c;
                                        wrapCon.ElectricityCurrentRedeliveryNum=string.valueof(consent.ElectricityCurrentRedeliveryNum__c);
                                        wrapCon.ElectricityCurrentRedeliveryLowNum=string.valueof(consent.ElectricityCurrentRedeliveryLowNum__c);
                                        wrapCon.MeterTariffChoice=consent.MeterTariffChoice__c;
                                        wrapCon.PhoneNumber=string.valueof(consent.PhoneNumber__C);
                                        wrapCon.EmailAddress=consent.EmailAddress__c;
                                        wrapCon.Main_Street=consent.Main_Street__c;
                                        wrapCon.Main_Street=consent.Main_addition__c;
                                        wrapCon.Main_Number=string.valueof(consent.Main_Number__c);
                                        wrapCon.Main_PostalCode=consent.Main_PostalCode__c;
                                        wrapCon.Main_City=consent.Main_City__c;
                                        wrapCon.Exclude_from_Surveys=string.valueof(consent.Exclude_from_Surveys__c);

                                        system.debug('wrapCon ' + wrapCon); //checkin Log your wrapCon is generated Properly with all fields
                                        allCon.add(wrapCon);                                   
                  } //Closing of for looop
            //No return Type is need for this method, as i change to void.
        }

        public void generateConsentlist() {
           consentFilter();
        }

        public class WrapConsent{
            public string coutOfid{set;get;}
            public string accid{set;get;}
            public string name{set;get;}
            public string Salutation{set;get;}
            public string FirstName{set;get;}
            public string Initials{set;get;}
            public string LastNamePrefix{set;get;}
            public string LastName{set;get;}
            public string ElectricityCurrentRedeliveryNum{set;get;}
            public string ElectricityCurrentRedeliveryLowNum{set;get;}
            public string MeterTariffChoice{set;get;}
            public string PhoneNumber{set;get;}
            public string EmailAddress{set;get;}
            public string Main_Street{set;get;}
            public string Main_Number{set;get;}
            public string Main_PostalCode{set;get;}
            public string Main_City{set;get;}
            public string Exclude_from_Surveys{set;get;}
            public string Main_addition{set;get;}        
        } 
    }
0
0

Your code has a number of problems, but the first, obvious problem is that your consentFilter() function doesn't actually add any wrapper items to the list. Make sure you do so:

       WrapConsent wrapCon=new WrapConsent();
       // ...
       allCon.add(wrapCon);

Your method will also ideally want to clear the list each time before doing the queries:

allCon.clear();

Otherwise, your results will stack up until you eventually hit an iteration limit.


It looks like you narrowly avoided an infinite recursion call:

    return null;
    return consentFilter();

"return" should be the last line of code in a method or block. Nothing after it will execute.


Generally speaking, you should avoid returning a PageReference type if you're never going to redirect. It's simply not necessary:

public void consentFilter()

The following code will only ever work if startDate and endDate is not null, otherwise the value will remain unchanged:

    if(startDate!=NULL&&EndDate!=NULL)
    {
        if(startDate!=NULL&&EndDate!=NULL)
        {              
            store=1;
        }
        else
        {
            store=0;
        }
    }

Take out the outer if statement:

if(startDate!=NULL&&EndDate!=NULL)
{              
    store=1;
}
else
{
    store=0;
}

Many of your String.valueOf method calls most likely unnecessary, consider revising.

2
  • @nithesh on using the code updated -- I am getting the error Class.Consent_Records_Ctrls.consentFilter: line 16, column 1
    – NCSS
    Commented Aug 11, 2017 at 8:15
  • I've been able to over come that error but still the records are not visible the moment I click on the filter it gives me the same error and the records are not visible in Chrome & Firefox
    – NCSS
    Commented Aug 11, 2017 at 8:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .