Displaying records based on parents name
Visualforce Page
<apex:page
sidebar="false" controller="AccWithAllContactsClass">
<apex:form >
<apex:inputtext
value="{!accName}" />
<apex:commandButton
value="ShowContacts" action="{!showContacts}"
rerender="out" status="mystatus"/><br/>
<apex:actionstatus
id="mystatus" starttext="please wait it is loading
contacts.......">
<apex:facet name="stop">
<apex:outputpanel
id="out">
<apex:pageBlock >
<apex:pageBlockSection >
<apex:pageBlockTable
value="{!conRecords}" var="c">
<apex:column
headerValue="Contacts">
{!c.Name}
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:outputpanel>
</apex:facet>
</apex:actionstatus>
</apex:form>
</apex:page>
Apex Class
public
with sharing class AccWithAllContactsClass {
List<Account> lstaccount = new
List<Account>();
List<contact> lstcontacts = new
List<contact>();
public List<contact> getConRecords()
{
lstcontacts.clear();
accIds.clear();
lstaccount.clear();
system.debug('****AccNameTextValue is
*****'+accName);
lstaccount=[select id,name from Account
where name=:accName];
for(Integer
i=0;i<lstaccount.size();i++)
{
accIds.add(lstaccount[i].Id);
}
lstcontacts =[select id,name,accountId
from contact where accountid in : accIds];
system.debug('**** List of Contacts for
Test is ***'+lstcontacts);
return lstcontacts;
}
set<string> accIds = new
set<string>();
public pagereference showContacts() {
return null;
}
public String accName { get; set; }
}
Displaying records based on parents name
Reviewed by dasfrogpractice
on
04:53
Rating:
No comments: