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
venk1255venk1255 

Displaying Records in Vfpage in monthly wise

Hi

 

display total number of Account created on month wise. Should have two column with header Monthwise and Number of accounts are created on that particular month.

 

Like this

 

Account created In              No of accounts created

Jan                            25

feb                            20

 

can any one provide me a sample code how to achive this it would be great thankfull.

 

Thanks In Advance

srini.SFDCsrini.SFDC

Hi i think u got solution  for this  senario..

 

please reply me if u have any ..

 

 

please let me know 

 

 

thanks,,,,

APathakAPathak

Hi,

Please try the below code :

VF page-

 

<apex:page standardController="account" extensions="hello22controller" showheader="false" sidebar="false">
    <apex:pagemessages ></apex:pagemessages>  
    <apex:pageblock>
		<apex:pageBlocktable value="{!laccountInfo}" var="ainfo">
			<apex:column value="{!ainfo.month}" headervalue="Month"/>
			<apex:column value="{!ainfo.count}" headervalue="No of accounts created"/>
		</apex:pageBlocktable>
	</apex:pageblock>
</apex:page>

 Controller -

public class hello22controller 
{
    public List <accountInfo> laccountInfo{get;set;}
    //Constructor
	public hello22controller(ApexPages.StandardController controller) 
    {
        laccountInfo = new list <accountInfo>();
		for(integer i=0;i<System.now().month();i++)
		{
			accountInfo ainfo = new accountInfo();
			ainfo.month = datetime.newinstance(2013,1,1).addmonths(i).format('MMM');
			ainfo.count = 0;
			laccountInfo.add(ainfo);
		}
		AggregateResult[] groupedResults  = [SELECT Count(id)monthCount,CALENDAR_MONTH(createdDate)                                                                monthNo FROM Account WHERE createdDate = THIS_YEAR GROUP BY CALENDAR_MONTH(createdDate)];
        
        for (AggregateResult ag : groupedResults)  
        {
            Integer MonthNo = integer.valueof(ag.get('monthNo'));
			Integer MonthCount = integer.valueOf(ag.get('monthCount'));
			laccountInfo.get(MonthNo-1).count = MonthCount;
        }                
    }
    //Wrapper Class
    public class accountInfo
    {
        public String month{get;set;}
        public integer count{get;set;}    
    }
}