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
sangam vvsangam vv 

Guys please help me i am stuck in this VF Page?

Guys I have 2 objects 
Account(Parent)
opportunity(child)

Assume that Requirement like this

For Example:

Account(HP)----have 1000 opportunity

           In this 200 Qualified
               400 Un-Qualified
           400 Prospecting

In visual force page I want to see for Qualified(Total 200)
This week   Last week    This month    Last Month       today =  Total Qualified leads 
   20                 40                80                 120             0  =     200


In visual force page I want to see for Un qualified(400)
This week   Last week   This month  Last Month        today =  Total Qualified leads 
   200         40                     240             160                  0  =                400



Like this I want to see in VF page I tried But View State is reached more thn 135kb
How To Do using Map
mritzimritzi
Apex:
public class TestClass2 { 
  public List<SampleClass> scList{get;set;}
  
  List<Account> acList;
  //qualified opportunity list
  List<Opportunity> opListQ;
  //unqualified opportunity list
  List<Opportunity> opListUQ;
    
  public TestClass2(){
     scList = new List<SampleClass>();
     acList = [Select Id,name From Account];
     //please check each line for syntax errors as per your org data (field name apis, strings like Qualified, Un Qualified etc)
     opListQ = [Select id, CreatedDate, AccountId From Opportunity Where StageName='Qualified' AND AccountID IN: acList];
     opListUQ = [Select id, CreatedDate, AccountId From Opportunity Where StageName='UnQualified' AND AccountID IN: acList];
     
     otherFunction();
  }
  public void otherFunction(){
      Date today = Date.Today();
      //cWeek -> date of first day of current week, other fields follow similar pattern
      Date cWeek,lWeek,cMonth,lMonth;
      cWeek = today - today.day() +1;// for first day of the month
      lWeek=cWeek-7;
      cMonth = today.toStartOfMonth(); //first date of current month
      lMonth = cMonth - 1; // last date of prev month
      lMonth = lMonth.toStartOfMOnth(); // first date of prev month      
      
      //iterating over acList, opListQ and opListUQ to populate scList (sampleClass List), sample class List data will be visible on VF Page   
      for(Integer i=0;i<acList.size();i++){
          SampleClass sc = new SampleClass();
          sc.ac = acList[i];
          for(Integer j=0;j<opListQ.size();j++){
              if(acList[i].id==opListQ[j].AccountId){
                  sc.opCountTotalQ+=1;
                  if(opListQ[j].createdDate>=lMonth && opListQ[j].createdDate <cMonth)
                      sc.opCountLMonthQ+=1;
                  else if(opListQ[j].createdDate>=cMonth){
                      sc.opCountCMonthQ+=1;
                      if(opListQ[j].createdDate>=lWeek && opListQ[j].createdDate <=cWeek)
                          sc.opCountLWeekQ+=1;
                      else if(opListQ[j].createdDate>=cWeek)
                          sc.opCountCWeekQ+=1;
                  }
                  //remove once matched opportunity from list to reduce inner iterations in subsequent loops
                  opListQ.remove(j);
              }
          }
          for(Integer j=0;j<opListQ.size();j++){
               if(acList[i].id==opListQ[j].AccountId){
                  sc.opCountTotalUQ+=1;
                  if(opListUQ[j].createdDate>=lMonth && opListUQ[j].createdDate <cMonth)
                      sc.opCountLMonthUQ+=1;
                  else if(opListUQ[j].createdDate>=cMonth){
                      sc.opCountCMonthUQ+=1;
                      if(opListUQ[j].createdDate>=lWeek && opListUQ[j].createdDate <=cWeek)
                          sc.opCountLWeekUQ+=1;
                      else if(opListUQ[j].createdDate>=cWeek)
                          sc.opCountCWeekUQ+=1;
                  }
                  opListUQ.remove(j);
              }
          }
          scList.add(sc);
      }
  }
  
  
  // a custom class to hold data as per your requirement
  public class SampleClass{
      public Account ac{get;set;}
      // opCountCWeekQ -> oppotunity count Current Week qualified, other names follow similar pattern
      public Integer opCountCWeekQ{get;set;}
      public Integer opCountLWeekQ{get;set;}
      public Integer opCountCMonthQ{get;set;}
      public Integer opCountLMonthQ{get;set;}
      public Integer opCountTodayQ{get;set;}
      public Integer opCountTotalQ{get;set;}
      
       public Integer opCountCWeekUQ{get;set;}
      public Integer opCountLWeekUQ{get;set;}
      public Integer opCountCMonthUQ{get;set;}
      public Integer opCountLMonthUQ{get;set;}
      public Integer opCountTodayUQ{get;set;}
      public Integer opCountTotalUQ{get;set;}
      
      public SampleClass(){
          opCountCWeekQ=opCountLWeekQ=opCountCMonthQ=opCountLMonthQ=opCountTodayQ=opCountTotalQ=0;
          opCountCWeekUQ=opCountLWeekUQ=opCountCMonthUQ=opCountLMonthUQ=opCountTodayUQ=opCountTotalUQ=0;
      }
  }
}

VF:
<apex:page controller="TestClass2" standardStylesheets="false">
  <apex:form >
      
          <apex:repeat value="{!scList}" var="sc">
          <table style="border:2px solid black;">
              <tr>
                  <td colspan="3"><h2> Account Name: </h2></td>
                  <td colspan="3"><h2> {!sc.ac.Name} </h2></td>
              </tr>
              <tr>
                  <td colspan="6">Qualified Opportunity Summary</td>
              </tr>
              <tr>
                  <td> This Week: </td>
                  <td> Last Week: </td>
                  <td> This Month: </td>
                  <td> Last Month: </td>
                  <td> Today: </td>
                  <td><b> Total: </b></td>
              </tr>
              <tr>
                  <td> {!sc.opCountCWeekQ} </td>
                  <td> {!sc.opCountLWeekQ} </td>
                  <td> {!sc.opCountCMonthQ} </td>
                  <td> {!sc.opCountLMonthQ} </td>
                  <td> {!sc.opCountTodayQ} </td>
                  <td> {!sc.opCountTotalQ} </td>
              </tr>
              <tr>
                  <td colspan="6">Un-Qualified Opportunity Summary</td>
              </tr>
              <tr>
                  <td> This Week: </td>
                  <td> Last Week: </td>
                  <td> This Month: </td>
                  <td> Last Month: </td>
                  <td> Today: </td>
                  <td><b> Total: </b></td>
              </tr>
              <tr>
                  <td> {!sc.opCountCWeekUQ} </td>
                  <td> {!sc.opCountLWeekUQ} </td>
                  <td> {!sc.opCountCMonthUQ} </td>
                  <td> {!sc.opCountLMonthUQ} </td>
                  <td> {!sc.opCountTodayUQ} </td>
                  <td> {!sc.opCountTotalUQ} </td>
              </tr>
              <tr>
              
              </tr>
          </table><br/>
          </apex:repeat>
      
  </apex:form>
</apex:page>

Change parameters name as per your choice.
Change field API names and their values in the code as per your Org data.


If this solves your problem, Mark it as Best Answer
sangam vvsangam vv
Bro I am gettinf value Zeros

User-added image
mritzimritzi
Please check a few things:
  • Do you have related opportunities for Accounts that match said criteria?
  • StageName ->  is this the API name of the field where you are storing values like "Qualified, "Un Qualified" etc ?
  • Have you confirmed that the values stored are exactly same as used in above code -> "Qualified" ,"UnQualified" or they are somewhat different ? (change these values exactly according to stored values)
If none of these work for you, kindly share screenshot of any one account record along with related opportunities and screenshto of all field details of Opportunity (specially custom fields)

Hope it helps.
sangam vvsangam vv
sorry friends please replace instead of opportunity i am using Leads(standard contacts)
accounts(parent)





User-added image



standard Contact(in project i am using as a lead)


User-added image
mritzimritzi
If you are dealing with leads then make changes accodingly (replace opportunity with leads) and change field names as per your org data. And you can excute above code.

Hope it helps.
sangam vvsangam vv
friends i changed everything i replaced  now i am getting like thisUser-added image
mritzimritzi
Contacts & Leads are two separate objects in Salesforce. please don't mix one with another. Each one has got its own specific usage. Please don't misue these objects.

Please use the Correct API name of the object from where you are fetching values and change field names according to the field names in that particular object.

If you are fetching records from Account and Lead use API Account and Lead respectively in SOQL query.
If you are fetching records from Contact and Lead use API Contact and Lead respectively in SOQL query.
If you are fetching records from Account and Conact use API Account and Conact respectively in SOQL query.
If you are fetching records from Account and Opportunity use API Account and Opportunity respectively in SOQL query.
sangam vvsangam vv
friends now error clear but it is not counting 
  1. User-added image
sangam vvsangam vv
still it s showng zero only
sangam vvsangam vv
visual force page

<apex:page controller="TestClass2" standardStylesheets="false">
  <apex:form >
      <apex:pageBlock >
      <table border = "1">
          <apex:repeat value="{!scList}" var="sc">
          <table style="border:0px solid black;">
              <tr>
                  <td colspan="3"><h2> Account Name: </h2></td>
                  <td colspan="3"><h2> {!sc.ac.Name} </h2></td>
              </tr>
              <tr>
                  <td colspan="6">Qualified Opportunity Summary</td>
              </tr>
              <tr>
                  <td> This Week: </td>
                  <td> Last Week: </td>
                  <td> This Month: </td>
                  <td> Last Month: </td>
                  <td> Today: </td>
                  <td><b> Total: </b></td>
              </tr>
              <tr>
                  <td> {!sc.opCountCWeekQ} </td>
                  <td> {!sc.opCountLWeekQ} </td>
                  <td> {!sc.opCountCMonthQ} </td>
                  <td> {!sc.opCountLMonthQ} </td>
                  <td> {!sc.opCountTodayQ} </td>
                  <td> {!sc.opCountTotalQ} </td>
              </tr>
              <tr>
                  <td colspan="6">Un-Qualified Opportunity Summary</td>
              </tr>
              <tr>
                  <td> This Week: </td>
                  <td> Last Week: </td>
                  <td> This Month: </td>
                  <td> Last Month: </td>
                  <td> Today: </td>
                  <td><b> Total: </b></td>
              </tr>
              <tr>
                  <td> {!sc.opCountCWeekUQ} </td>
                  <td> {!sc.opCountLWeekUQ} </td>
                  <td> {!sc.opCountCMonthUQ} </td>
                  <td> {!sc.opCountLMonthUQ} </td>
                  <td> {!sc.opCountTodayUQ} </td>
                  <td> {!sc.opCountTotalUQ} </td>
              </tr>
              <tr>
              
              </tr>
          </table><br/>
          </apex:repeat>
          </table>
      </apex:pageblock>
  </apex:form>
</apex:page>
 
Controller

public class TestClass2 { 
  public List<SampleClass> scList{get;set;}
  
  List<Account> acList;
  
  
  //qualified Contact list
  List<Contact> opListQ;
  //unqualified Contact list
  List<Contact> opListUQ;
    
  public TestClass2(){
     scList = new List<SampleClass>();
     acList = [Select Id,name From Account];
     //please check each line for syntax errors as per your org data (field name apis, strings like Qualified, Un Qualified etc)
     opListQ = [Select id, CreatedDate, AccountId From Contact Where Lead_Status__c='Qualified' AND AccountID IN: acList];
     opListUQ = [Select id, CreatedDate, AccountId From Contact Where Lead_Status__c='UnQualified' AND AccountID IN: acList];
     
     otherFunction();
  }
  public void otherFunction(){
      Date today = Date.Today();
      //cWeek -> date of first day of current week, other fields follow similar pattern
      Date cWeek,lWeek,cMonth,lMonth;
      cWeek = today - today.day() +1;// for first day of the month
      lWeek=cWeek-7;
      cMonth = today.toStartOfMonth(); //first date of current month
      lMonth = cMonth - 1; // last date of prev month
      lMonth = lMonth.toStartOfMOnth(); // first date of prev month      
      
      //iterating over acList, opListQ and opListUQ to populate scList (sampleClass List), sample class List data will be visible on VF Page   
      for(Integer i=0;i<acList.size();i++){
          SampleClass sc = new SampleClass();
          sc.ac = acList[i];
          for(Integer j=0;j<opListQ.size();j++){
              if(acList[i].id==opListQ[j].AccountId){
                  sc.opCountTotalQ+=1;
                  if(opListQ[j].createdDate>=lMonth && opListQ[j].createdDate <cMonth)
                      sc.opCountLMonthQ+=1;
                  else if(opListQ[j].createdDate>=cMonth){
                      sc.opCountCMonthQ+=1;
                      if(opListQ[j].createdDate>=lWeek && opListQ[j].createdDate <=cWeek)
                          sc.opCountLWeekQ+=1;
                      else if(opListQ[j].createdDate>=cWeek)
                          sc.opCountCWeekQ+=1;
                  }
                  //remove once matched Contact from list to reduce inner iterations in subsequent loops
                  opListQ.remove(j);
              }
          }
          for(Integer j=0;j<opListQ.size();j++){
               if(acList[i].id==opListQ[j].AccountId){
                  sc.opCountTotalUQ+=1;
                  if(opListUQ[j].createdDate>=lMonth && opListUQ[j].createdDate <cMonth)
                      sc.opCountLMonthUQ+=1;
                  else if(opListUQ[j].createdDate>=cMonth){
                      sc.opCountCMonthUQ+=1;
                      if(opListUQ[j].createdDate>=lWeek && opListUQ[j].createdDate <=cWeek)
                          sc.opCountLWeekUQ+=1;
                      else if(opListUQ[j].createdDate>=cWeek)
                          sc.opCountCWeekUQ+=1;
                  }
                  opListUQ.remove(j);
              }
          }
          scList.add(sc);
      }
  }
  
  
  // a custom class to hold data as per your requirement
  public class SampleClass{
      public Account ac{get;set;}
      // opCountCWeekQ -> oppotunity count Current Week qualified, other names follow similar pattern
      public Integer opCountCWeekQ{get;set;}
      public Integer opCountLWeekQ{get;set;}
      public Integer opCountCMonthQ{get;set;}
      public Integer opCountLMonthQ{get;set;}
      public Integer opCountTodayQ{get;set;}
      public Integer opCountTotalQ{get;set;}
      
       public Integer opCountCWeekUQ{get;set;}
      public Integer opCountLWeekUQ{get;set;}
      public Integer opCountCMonthUQ{get;set;}
      public Integer opCountLMonthUQ{get;set;}
      public Integer opCountTodayUQ{get;set;}
      public Integer opCountTotalUQ{get;set;}
      
      public SampleClass(){
          opCountCWeekQ=opCountLWeekQ=opCountCMonthQ=opCountLMonthQ=opCountTodayQ=opCountTotalQ=0;
          opCountCWeekUQ=opCountLWeekUQ=opCountCMonthUQ=opCountLMonthUQ=opCountTodayUQ=opCountTotalUQ=0;
      }
  }
}

Account is a Parent(standard)
Contact is a child(standad)
 
mritzimritzi
Please check whether the picklist field Lead_Status__c has value exactly similar to   "Qualified" and "UnQualified" stored.

because i saw previous images and noticed that one such value was "Unqualified" please write the Lead_Status__c value in Apex EXACTLY  as its stored in field. Else if wont fetch any record. Values are case sensitive.

In the apex code you have shared above, kindly replace code from line 53-67 with following code:
for(Integer j=0;j<opListUQ.size();j++){
               if(acList[i].id==opListUQ[j].AccountId){
                  sc.opCountTotalUQ+=1;
                  if(opListUQ[j].createdDate>=lMonth && opListUQ[j].createdDate <cMonth)
                      sc.opCountLMonthUQ+=1;
                  else if(opListUQ[j].createdDate>=cMonth){
                      sc.opCountCMonthUQ+=1;
                      if(opListUQ[j].createdDate>=lWeek && opListUQ[j].createdDate <=cWeek)
                          sc.opCountLWeekUQ+=1;
                      else if(opListUQ[j].createdDate>=cWeek)
                          sc.opCountCWeekUQ+=1;
                  }
                  opListUQ.remove(j);
              }
          }



Mark it as Best Answer if it helps.
sangam vvsangam vv
still same output no change
i change code and picklist values also