In this scenario we have shown, how to display Account related contacts in alert message using vf page.
Apex Controller
public class AccountRelatedContactInAlert {
public List<wrapper> wrapperList{get; set;}
public List<Contact> contactsInformation { get; set; }
public Id selectedCountOfContact { get; set; }
public AccountRelatedContactInAlert(){
wrapperList=new List<Wrapper>();
for(Account a:[select id,Name,industry,Phone,(select id,name from contacts) from Account limit 5])
{
Wrapper w1=new Wrapper();
w1.Name=a.Name;
w1.Phone = a.Phone;
w1.Industry = a.Industry;
w1.Con=a.contacts.size();
w1.recordid =a.id;
wrapperList.add(w1);
}
}
class Wrapper{
public string Phone{get; set;}
public String Name{get; set;}
public String Industry{get; set;}
public Integer Con{get; set;}
public Id recordid{get; set;}
}
public List<Account> getMyAccounts() {
return [SELECT Id, Name,Industry,Phone FROM Account ORDER BY
LastModifiedDate DESC LIMIT 10];
}
public void accountClicked() {
contactsInformation = [SELECT FirstName, LastName FROM Contact
WHERE AccountID = :selectedCountOfContact];
}
}
Visualforce Page
<apex:page controller="AccountRelatedContactInAlert">
<apex:form >
<apex:outputPanel id="ContactDetail">
<apex:repeat value="{!contactsInformation}" var="contact">
<script type="text/javascript">
alert("{!contact.LastName}");
</script>
</apex:repeat>
</apex:outputPanel>
<apex:pageBlock >
<apex:pageBlockTable value="{!wrapperList}" var="b" >
<apex:column headerValue="Account Name">
<apex:commandlink action="{!accountClicked}" rerender="ContactDetail">
{!b.Name}
<apex:param name="id" value="{!b.recordid}" assignTo="{!selectedcountofcontact}"/>
</apex:commandlink>
</apex:column>
<apex:column value="{!b.Industry}" headerValue="Industry"></apex:column>
<apex:column value="{!b.Phone}" headerValue="Phone"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Output