• Apoorv Sharma
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies

hi

     i wrote a code for displaying account and its related contacts using wrapperclass

now my requirement is i have button called show contacts if i click dat button it has to show account and its related contacts .

i am pasting  my code here can anyone do modifications and revert.

 

----------------------vfpage-----------------------

<apex:page controller="MainWrapperClass">
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!DifferentObject}" var="Dodata">
<apex:column value="{!Dodata.Accname}" headerValue="Account"/>
<apex:column value="{!Dodata.Conname}" headerValue="Contact"/>
</apex:pageBlockTable>
</apex:pageBlock>
<apex:commandButton value="Show Contacts" action="{!contacts}"/>
</apex:form>
</apex:page>

 

 

---------------------------controller-------------------------

 

public Class MainWrapperClass
{

public string Differentobject{get;set;}
public String Accname{get;set;}
public String Conname{get;set;}
public String AccountName='';
public String ContactName='';
public id id1='0019000000Cd9lLAAR';
public id id2='0039000000DNmUS';

public WrapperClass getDifferentObject()
{
Account Varacc=[Select id,name from Account where id=:id1];

AccountName=Varacc.name;
wrapperClass Wc=new wrapperClass(AccountName,ContactName);
return wc;
}

public PageReference contacts()
{

List<Contact> Varcon=[Select Accountid,lastname from Contact where Accountid in(select id from account where id=:id1)];

if(!Varcon.isEmpty())
{

for(Contact cnt: Varcon)
//for(Integer i=0;i<=1;i++)
{
if(cnt.Lastname!=null)
{
ContactName+=cnt.Lastname+',';
}
}
}

return null;
}
public Class wrapperClass
{
public String Accname{get;set;}
public String Conname{get;set;}
public wrapperClass(String Aname,String Cname)
{
Accname=Aname;
Conname=Cname;
}
}


}

 

Thanksin advance