+ Start a Discussion
Kiran Kumar GottulaKiran Kumar Gottula 

Dispaly opportunity records in table , week wise

I want to display 2 weeks Opportunities  data in the fallowing table.

 

How to display ....?

Please help me 

 

 

    Statistics                                                      This Week (opportunities)           Previous Week (opportunities)    

 

Total Amount(Sum of Amount )                                             4000                           4500

 No of Opp (Count)                                                                     10                                 12

AsitM9AsitM9
Date d=system.toDay();
d=Date.newInstance(d.year(),d.month(),d.day()-7);
List<OPPORTUNITY > opp=[SELECT ID FROM OPPORTUNITY WHERE CREATEDDATE<TODAY AND CREATEDDATE>:d];

 This SOQL will return the opportunity created in last week.

deepabalisfdcdeepabalisfdc

Hi,
I have no record for prev wekk in Databse. I am only writing for today.
You need to write 2 soqls for prev week only.First you run and see, today's Opp detail are right.
This is page

<apex:page controller="testForSFDC">
<apex:pageBlock>
  <apex:pageBlockSection>
  <apex:pageBlockTable value="{!oppClassobjlist}" var="records" id="PagePanelId" style="width:90%" >                     
                  <apex:column headerValue="Statistics">
                      <apex:outputLabel value="{!records.stat}"/>
                  </apex:column>
                  <apex:column headerValue="This Week">
                      <apex:outputLabel value="{!records.thisWeek}"/>
                  </apex:column>
                  <apex:column headerValue="Prev Week">
                      <apex:outputLabel value="{!records.prevWeek}"/>
                  </apex:column>
 </apex:pageBlockTable><br/>
 </apex:pageBlockSection>
 </apex:pageBlock>
</apex:page>

 This is class:

public class testForSFDC{
public list<OppInnerClass > oppClassobjlist{get;set;}

public testForSFDC(){
     oppClassobjlist = new list<OppInnerClass >();
     
     List<String> subjectsList = new List<String>();
     subjectsList.add('Total Amount(Sum of Amount )');
     subjectsList.add(' No of Opp (Count) ');
     
     for(Integer i=0; i<=subjectsList.size()-1;i++){
         String statObj = '';
         Integer countthisWeek = 0;
         Integer countPrevWeek= 0;
         if(i==0){
             statObj = subjectsList.get(0);
             Date d=system.toDay();
             d=Date.newInstance(d.year(),d.month(),d.day()-7);
             AggregateResult[] groupedResults = [SELECT Sum(Amount)amt FROM Opportunity WHERE  CREATEDDATE=Today ]; 
             for(AggregateResult ar : groupedResults ){
                 countthisWeek = Integer.valueOf(ar.get('amt'));
             }
//write code here to have value for prev week sum amt and set to countPrevWeek
             
         }
         if(i==1){
             statObj = subjectsList.get(1);
             Date d=system.toDay();
             d=Date.newInstance(d.year(),d.month(),d.day()-7);
             //Only for today
             AggregateResult[] groupedResults = [SELECT Count(Id)opptot FROM Opportunity WHERE  CREATEDDATE=Today ];
             for(AggregateResult ar : groupedResults ){
                 countthisWeek = Integer.valueOf(ar.get('opptot'));
             }

    //write code here to have value for prev week count of Opp and set to countPrevWeek variable        
         }
         OppInnerClass oppClassobj=new OppInnerClass(statObj,countthisWeek,countPrevWeek);
         oppClassobjlist.add(oppClassobj);
     }
    
}
public class OppInnerClass
{  
        public String stat { get;set; }  
      
        public Integer thisWeek{ get;set; }    
       
        public Integer prevWeek{ get;set; }  
           
        public OppInnerClass(String statparam,Integer thisWeekparam,Integer prevWeekParam)  
        {  
           stat = statparam;  
           thisWeek = thisWeekparam;
           prevWeek = prevWeekParam;
        }
}

}

 Thank you

:

Bhawani SharmaBhawani Sharma
You need to write a aggregate query. Group by your data by calender week.
This is not an exact syntex, but query will be similar to something:
Select SUM(Amount) tAmount, Count(Id) counter from Opportunity Group By CalenderWeek(CreatedDate)