+ Start a Discussion
carlosumana421carlosumana421 

Visual Force Page with Column for Each Opportunity Stage

Hello,

 

I have been presented with a new requirement and am at my wits end as to how to start off. I am a newbie to this so please be gentle with me.

 

What our company is looking for is a visualForce opage that has a column for each opportunity stage and populates the opportunity name and amount for the specific rep that opens the page(would be a tab).  I.e

 

Propsect                         Needs Analysis(25%)                                                       Presentation (50%)      

Opp. A $1,200                Opp D $5,600                                                                     Opp M $7,800         

Opp. X $1,200                Opp K $5,600                                                                      Opp V $7,800

Opp. L $1,200                Opp C $5,600                                                                      Opp W $7,800

 

                                         Total =25%*sum of opps in stage                                  Total=50%*sum of Opps in Stage

wajidawajida

public class StageOpp {   public list<opportunity> listOfOpp;   public string s;   public list<string> picklistVals;   public list<list<opportunity>> stagelist = new list<list<opportunity>>();    public list<string> getPicklistVals() {    picklistVals = new list<string>();    Schema.DescribeFieldResult fieldResult = opportunity.stageName.getDescribe();     for(Schema.PicklistEntry f  :  fieldResult.getPicklistValues()){     picklistVals.add(f.getValue());    }     return picklistVals;        }   public list<list<opportunity>> getOpportunities(){        list<string> pv = new list<string>();        Schema.DescribeFieldResult fr = opportunity.stageName.getDescribe();               for(Schema.PicklistEntry p  :  fr.getPicklistValues()){         pv.add(p.getValue());    }          for(Integer i = 0; i < pv.size(); i++){          String pvalue = pv[i];          listOfOpp = [select id, name, stagename, amount from opportunity where stagename = :pvalue];        stagelist.add(listOfOpp);              }       return stagelist;      }      public list<opportunity> getProspecting(){          list<string> pv = new list<string>();        Schema.DescribeFieldResult fr = opportunity.stageName.getDescribe();               for(Schema.PicklistEntry p  :  fr.getPicklistValues()){         pv.add(p.getValue());    }          for(Integer i = 0; i < pv.size(); i++){          String pvalue = pv[i];          listOfOpp = [select id, name, stagename, amount from opportunity where stagename = :pvalue];        stagelist.add(listOfOpp);              }

       list<opportunity> prospecting = new list<opportunity>();       prospecting =  stagelist[0];        return prospecting;       }       public list<opportunity> getQualification(){          list<string> pv = new list<string>();        Schema.DescribeFieldResult fr = opportunity.stageName.getDescribe();               for(Schema.PicklistEntry p  :  fr.getPicklistValues()){         pv.add(p.getValue());    }          for(Integer i = 0; i < pv.size(); i++){          String pvalue = pv[i];          listOfOpp = [select id, name, stagename, amount from opportunity where stagename = :pvalue];        stagelist.add(listOfOpp);              }

       list<opportunity> qualification = new list<opportunity>();       Qualification =  stagelist[1];        return qualification;       }       public list<opportunity> getNeedsAnalysis(){          list<string> pv = new list<string>();        Schema.DescribeFieldResult fr = opportunity.stageName.getDescribe();               for(Schema.PicklistEntry p  :  fr.getPicklistValues()){         pv.add(p.getValue());    }          for(Integer i = 0; i < pv.size(); i++){          String pvalue = pv[i];          listOfOpp = [select id, name, stagename, amount from opportunity where stagename = :pvalue];        stagelist.add(listOfOpp);              }

       list<opportunity> needsAnalysis = new list<opportunity>();       needsAnalysis =  stagelist[2];        return needsAnalysis;       }

}

 

<apex:page controller="StageOpp" tabStyle="Account">
  <apex:form >
  <apex:pageBlock >
    <apex:pageBlockSection title="Prospecting"> 
  <apex:repeat value="{!prospecting}" var="p">
    {!p.name}{!p.amount}  <br/>
    </apex:repeat>
   </apex:pageBlockSection>    
    <apex:pageBlockSection title="Qualification">  
   <apex:repeat value="{!qualification}" var="p">
    {!p.name}{!p.amount}  <br/>
  </apex:repeat>
  </apex:pageBlockSection>
  <apex:pageBlockSection title="Needs Analysis">  
   <apex:repeat value="{!NeedsAnalysis}" var="p">
    {!p.name}{!p.amount}  <br/>
  </apex:repeat>
  </apex:pageBlockSection>
    </apex:pageBlock>
 
  </apex:form> 
</apex:page>

 

I have put the stage values in pageblocksection instead of columns for which i think you will need html. I have had to write a lot of redundant code which i am sure I could of done without...if you find a better solution please let me know and also for the rest of the pick list values you can simply copy paste the code making small changes..hope you get it . I hope a better developer in this board would be able to throw some light on how to do this as i found it quite a challenging code to write