You need to sign in to do that
Don't have an account?
Deepak Pandey 13
opportunity stagename and thier record size
public class stagesize
{
public stagesize()
{
lstOpp = new List<Opp>();
stages = new list<string>();
Schema.DescribeFieldResult fieldResult = Opportunity.StageName.getDescribe();
System.debug(fieldResult);
List<Schema.PicklistEntry> pichlstval = fieldResult.getPicklistValues();
system.debug('--pichlstval -->>'+pichlstval );
for( Schema.PicklistEntry f : pichlstval )
{
stages.add(f.getLabel());
System.debug('@@@@@stages' +stages);
}
map < string , list<opportunity>> lststage = new map < string , list<opportunity>>();
for(Opportunity opp : [select id,Name,StageName from Opportunity])
{
if(lststage.get(opp.StageName)== null)
{
lststage.put(opp.StageName , new list<Opportunity>());
}
lststage.get(opp.StageName).add(opp);
System.debug('@@@@@lststage.size()' +lststage.size());
}
for(string opp : stages)
{
integer i = lststage.size();
String prefix = String.getCommonPrefix(stages);
System.debug('@@@@@i' +i );
System.debug('@@@@@prefix' +prefix );
Opp o = new opp(prefix , i);
lstOpp.add(o);
// lstOpp.add((prefix),(i));
}
}
public List<Opp> lstOpp {get;set;}
public List<string> stages {get;set;}
public class Opp
{
public String stage {get;set;}
public Integer size {get; set;}
public opp(string s , Integer I)
{
stage = s;
size = i ;
}
}
}
{
public stagesize()
{
lstOpp = new List<Opp>();
stages = new list<string>();
Schema.DescribeFieldResult fieldResult = Opportunity.StageName.getDescribe();
System.debug(fieldResult);
List<Schema.PicklistEntry> pichlstval = fieldResult.getPicklistValues();
system.debug('--pichlstval -->>'+pichlstval );
for( Schema.PicklistEntry f : pichlstval )
{
stages.add(f.getLabel());
System.debug('@@@@@stages' +stages);
}
map < string , list<opportunity>> lststage = new map < string , list<opportunity>>();
for(Opportunity opp : [select id,Name,StageName from Opportunity])
{
if(lststage.get(opp.StageName)== null)
{
lststage.put(opp.StageName , new list<Opportunity>());
}
lststage.get(opp.StageName).add(opp);
System.debug('@@@@@lststage.size()' +lststage.size());
}
for(string opp : stages)
{
integer i = lststage.size();
String prefix = String.getCommonPrefix(stages);
System.debug('@@@@@i' +i );
System.debug('@@@@@prefix' +prefix );
Opp o = new opp(prefix , i);
lstOpp.add(o);
// lstOpp.add((prefix),(i));
}
}
public List<Opp> lstOpp {get;set;}
public List<string> stages {get;set;}
public class Opp
{
public String stage {get;set;}
public Integer size {get; set;}
public opp(string s , Integer I)
{
stage = s;
size = i ;
}
}
}
You don't have to write these many lines of code. As a best practice you code use the aggregate soql.
Here is the updated class and the Vf page.
Hope your problem is solved