Skip to main content

public class AccountWrapper

{

public List<WrapperAccounts> wrapItems{set;get;}

public List<WrapperAccounts> wrapConItems{set;get;}

public List<WrapperAccounts> selectedItem{set;get;}

public List<Contact> accContacts{set;get;}

public Set<Id> accId=new Set<Id>();

public AccountWrapper()

{

wrapItems=new List<WrapperAccounts>();

List<Account> accItem2=new List<Account>([SELECT Name FROM Account limit 10]);

wrapConItems=new List<WrapperAccounts>();

for(Account a1:accItem2)

{

boolean check=false;

wrapItems.add(new WrapperAccounts(check,a1));

}

if(accId!=null)

{

for(Contact cx:conwrap)

{

wrapConItems.add(new WrapperAccounts(false,cx));

}

}

}

//Defining pagference to perform actionsupport onclick event

public PageReference fetch()

{

fetchRecords();

return null;

}

public PageReference fetchCont()

{

fetchConRecords();

return null;

}

//Method to define fetchRecords which will fetch Related Contacts

public void fetchRecords()

{

accContacts=new List<Contact>();

for(WrapperAccounts wraps : wrapItems)

{

if(wraps.selected==true)

{

accId.add(wraps.accList.Id);

}

System.debug('Selected Accounts:'+wraps);

}

System.debug('Accounts IDs:accId='+accId);

List<Contact> cons=[Select Name from Contact WHERE AccountId IN:accId];

for(Contact con:cons)

{

accContacts.add(con);

}

System.debug('Contacts Lists:'+accContacts);

}

//method to fetch contact's detail page

public Set<Id> conId=new Set<Id>();

public void fetchConRecords()

{

for(WrapperAccounts contwraps : wrapConItems)

{

if(contwraps.conSel==true)

{

conId.add(contwraps.contLists.Id);

}

System.debug('Selected Contacts:'+contwraps);

}

List<Contact> conx2=[Select Id from Contact WHERE Id IN:conId];

System.debug('Contacts Lists in conx2:'+conx2);

}

//Wrapper Class

public class WrapperAccounts

{

public boolean selected{set;get;}

public Account accList{set;get;}

public Contact contLists{set;get;}

public boolean conSel{set;get;}

public WrapperAccounts(Boolean sel,Account acc)

{

this.accList=acc;

this.selected=sel;

}

public WrapperAccounts(Boolean selec,Contact co)

{

this.conSel=selec;

this.contLists=co;

}

}

}

<apex:page controller="AccountWrapper" sidebar="false">

<apex:form >

<apex:pageBlock >

<apex:pageBlockButtons >

<!--<apex:commandButton value="Select" action="{!fetchRecords}" reRender="block2" rerender="block3"/>-->

</apex:pageBlockButtons>

<apex:pageBlockSection title="Accounts" columns="3">

<apex:pageBlockTable value="{!wrapItems}" var="c" id="table">

<apex:column headerValue="Select">

<apex:inputCheckbox value="{!c.selected}"/>

<apex:actionSupport event="onclick" action="{!fetch}"/>

</apex:column>

<apex:column value="{!c.accList.Name}" headerValue="Account Name"/>

</apex:pageBlockTable>

<apex:pageBlockTable value="{!accContacts}" var="c1" id="block2">

<apex:column headerValue="Select">

<!--<apex:inputCheckbox value="{!c1.conSel}"/>-->

<apex:actionSupport event="onclick" action="{!fetchCont}"/>

</apex:column>

<apex:column value="{!c1.Name}" headerValue="Related Contacts Name"/>

</apex:pageBlockTable>

<apex:pageBlockTable value="{!accContacts}" var="d1" id="block3">

<apex:column value="{!d1.Name}" headerValue="Contact Detail Page"/>

</apex:pageBlockTable>

</apex:pageBlockSection>

</apex:pageBlock>

</apex:form>

</apex:page>

 
22 respuestas
  1. 2 ago 2018, 10:18
    Sorry 

    Try this one

    <apex:page controller="AccountWrapper" sidebar="false">

    <apex:form >

    <apex:pageBlock >

                <apex:pageBlockButtons >

                <!--<apex:commandButton value="Select" action="{!fetchRecords}" reRender="block2" rerender="block3"/>-->

                </apex:pageBlockButtons>

                <apex:pageBlockSection title="Accounts" columns="3">

                <apex:pageBlockTable value="{!wrapItems}" var="c" id="table">

                    <apex:column headerValue="Select">

                       <apex:inputCheckbox value="{!c.selected}"/>

                       <apex:actionSupport event="onclick"  action="{!fetch}"/>

                    </apex:column>

                    <apex:column value="{!c.accList.Name}" headerValue="Account Name"/>

                </apex:pageBlockTable>

               

                

                <apex:pageBlockTable value="{!wrapConItems}" var="c1" id="block2">

                <apex:column headerValue="Select">

                       <apex:inputCheckbox value="{!c1.conSel}"/>

                       <apex:actionSupport event="onclick"  action="{!fetchCont}"/>

                    </apex:column>

                <apex:column value="{!c1.contLists.Name}" headerValue="Related Contacts Name"/>

                

                </apex:pageBlockTable>

                

                

                <apex:pageBlockTable value="{!conx2}" var="d1" id="DetailPageBlock">

                <apex:column value="{!d1.Name} {!d1.Phone}" headerValue="Contact Detail Page"/>

                <!--<apex:detail id=""/>-->

                </apex:pageBlockTable>

                </apex:pageBlockSection>

                

    </apex:pageBlock>

    </apex:form>

    </apex:page>