Skip to main content
Hi i have a requirement please find the below req and suugget me , or send my any related code is already developed .

Display all related opp records for a particualr account with the below conditions

1) Opportunities which are status= TRUE 

2) These Opportunities should have at least one Product.

3) This VF page should support Pagination, each page should have max of 25 record.

This VF page should have sorting in all the columns.

4) VF page should have i/p check box has to be present in front of every record.

i developed VF page for pagination for displaying account records but dont know how to to display one account related opportunities , please help me on this or send any code 

Regards,

Hanu
5 Antworten
  1. 20. Juni 2015, 06:22
    If you want to display all the accounts and opportunites then I have a code for you.

    In the below code I am displaying all accounts and opportunities and a checkbox we also have a functionality where I am displaying only the selected records.

    Have a look on the code and modify as per your needs.

    ⌗PAGE

    <apex:page controller="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>

    </apex:page>

    ⌗CLASS

    public class wrapperAccountOpportunity {

    public wrapperAccountOpportunity(){

    normalList = true;

    selectedList = false;

    fetchData();

    }

    public boolean normalList{get;set;}

    public boolean selectedList{get;set;}

    public void fetchData(){

    List<Opportunity> allOpps = [Select name,Id,AccountId from Opportunity ];

    //Parent Id set

    Set<id> parentIdSet = new Set<id>();

    //Create parent Id set

    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;

    }

    }

    }

    Let me know in case of any issue.

0/9000