0

I am trying to create a Vf page on click of a custom button "Show opportunities" on account detail page.Currently when i preview my Vf page it shows only two button "Proceed with Selected" & "Proceed with Selected to Next Page" button.I need to have pagination and checkbox against each opportunity against current account.I am using Apex as extension to the standard controller "Account".My apex class and VF page code are :

Apex class :

public with sharing class wrapperAccountOpportunity {

//private ApexPages.StandardSetController standardController;
public Account account{get;set;}
public wrapperAccountOpportunity(){
    normalList = true;
    selectedList = false;
    fetchData();
}
public wrapperAccountOpportunity(ApexPages.StandardController controller) {

this.account = (Account)controller.getRecord();        
}

public boolean normalList{get;set;}
public boolean selectedList{get;set;}
public void fetchData(){
    String var = ApexPages.currentPage().getParameters().get('account');
    List<Opportunity> allOpps = [Select name,Id,AccountId from Opportunity];
    Set<id> parentIdSet = new Set<id>();
    for(Opportunity OppertunityRec : allOpps){
        parentIdSet.add(OppertunityRec.AccountId);
    }
//Fetch all associated parents
    List<Account> allAssocaiatedAccounts = [Select name,id from Account where Id IN : parentIdSet];

    wrapperList = new list<myWrapperClass>();
    //For loop to set data
    for(Opportunity childRec : allOpps){
        //myWrapperClass wrapRec;
        for(Account parentRec :allAssocaiatedAccounts){
            if(parentRec.Id == childRec.AccountId){
                myWrapperClass wrapRec = new myWrapperClass();
                wrapRec.acc = parentRec;
                wrapRec.opp = childRec;
                wrapperList.add(wrapRec);
            }
        } 
        //Adding Opportunities without account
        if(childRec.AccountId == null){
                myWrapperClass wrapRec = new myWrapperClass();
                //wrapRec.acc = null;
                wrapRec.opp = childRec;
                wrapperList.add(wrapRec);
        }
    }

}
  public List<myWrapperClass> selectedWrapperList {get; set;}
public PageReference ProceedWithSelected(){
    selectedWrapperList = new List<myWrapperClass>();
    normalList = false;
    selectedList = true;
    for(myWrapperClass selectedWrapObj: wrapperList){
        system.debug('selectedWrapObj.selected  ---------'+selectedWrapObj.selected);
        if(selectedWrapObj.selected == true)
        selectedWrapperList.add(selectedWrapObj);
    }
    system.debug('selectedWrapperList size ---------'+selectedWrapperList.size());
    return null;
}
 public PageReference ProceedWithSelectedToNextPage(){
    selectedWrapperList = new List<myWrapperClass>();
    normalList = false;
    selectedList = true;
    for(myWrapperClass selectedWrapObj: wrapperList){
        system.debug('selectedWrapObj.selected  ---------'+selectedWrapObj.selected);
        if(selectedWrapObj.selected == true)
        selectedWrapperList.add(selectedWrapObj);
    }
    system.debug('selectedWrapperList size ---------'+selectedWrapperList.size());
    PageReference pageRef = new PageReference('/apex/AccountOpportunityTwoPage');
    pageRef.setRedirect(false);
    return pageRef;
}

//Wrapper list 
public List<myWrapperClass> wrapperList {get; set;}
//Your wrapper 
public class myWrapperClass{
public Account acc{get;set;}
public Opportunity opp{get;set;}
public Boolean selected {get; set;} 
public myWrapperClass() { 
     selected = false; 
  } 
}  


}

VisualForce Page:

  <apex:page standardController="Account" extensions="wrapperAccountOpportunity" sidebar="false">
  <apex:form >
  <apex:commandButton value="Proceed with Selected" action="{!ProceedWithSelected}" reRender="panelId"/>
  <apex:commandButton value="Proceed with Selected to Next Page" action="{!ProceedWithSelectedToNextPage}" />
  <apex:pageBlock >
    <apex:outputPanel id="panelId">
        <apex:pageblockTable value="{!wrapperList}" var="wrapRec" rendered="{!normalList}">
           <apex:column value="{!wrapRec.acc.Name}" />
           <apex:column value="{!wrapRec.opp.Name}"/>
           <apex:column >
               <apex:inputCheckbox value="{!wrapRec.selected}"/>
           </apex:column>
      </apex:pageblockTable>

       <apex:pageblockTable value="{!selectedWrapperList}" var="wrapRec" rendered="{!selectedList}">
           <apex:column value="{!wrapRec.acc.Name}" />
           <apex:column value="{!wrapRec.opp.Name}"/>
           <apex:column >
               <apex:inputCheckbox value="{!wrapRec.selected}"/>
           </apex:column>
      </apex:pageblockTable>
    </apex:outputPanel>      
</apex:pageBlock>
</apex:form>

I am not able to find what the errors are.

1 Answer 1

0

You are using two constructor for main class. One with passing ApexPages.StandardController controller method and another without any parameter.

As you are using controller extension in your VF page so this constructor public wrapperAccountOpportunity(ApexPages.StandardController controller) executing but you have called method fetchData(); in other constructor and it is not calling the method. This is the reason you are not able to show the data on the VF page.

I would suggest you to move you method to other constructor.

public wrapperAccountOpportunity(){

 //Move method from here.

}

public wrapperAccountOpportunity(ApexPages.StandardController controller) {

this.account = (Account)controller.getRecord();  

    normalList = true;
    selectedList = false;
    fetchData();

}

Its working in my org.

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .