+ Start a Discussion
anu deep 6anu deep 6 

check box functionality

Hi salesforce family,

followig functionality need to be achieved in below code.Please help me.

current functionality
----------------------------
1.)currently if we uncheck the check boxes of opportunitis and contacts and click submitt button all the contacts and opportunities records related to accounts are getting disappear.

required functionality
-----------------------------
1.)On uncheck the check boxs of opportunities and contacts with out clicking submitt button all the contacts and opportunities records related to accounts need to disappear.

2.)If we select the check boxs of opportunities and contacts with out clicking submitt button all the contacts and opportunities records related to accounts need to dispaly.

please try to achieve required functionality and also provide code coverage.

I here by providing code
=================
Apex class
---------------

public class Acc_con_Opp_Details
{
    
    //list of collection of the wrapper class object
    public list<accountwrapper> actwrap           {set;get;}
    //list of collection of Account,contact and opportunity objects
    public list<Account>        accounts          {set;get;}
    public list<Account>        acts              {set;get;}
    public list<opportunity>    opts              {set;get;}
    public list<opportunity>    sopts             {set;get;}
    public list<contact>        cnts              {set;get;} 
    public list<contact>        snts              {set;get;}
    public boolean oppbox                         {set;get;}//used as check box for opportunity 
    public boolean conbox                         {set;get;}//used as check box for contact
    public boolean flag1                          {set;get;}//used in account page block  
    public boolean flag2                          {set;get;}//used in contact page block 
    public boolean flag3                          {set;get;}//used in opportunity page block
    //this variables are used for pagination purpose
    private integer totalRecs = 0;//stores no.of total records   
    private integer index = 0;//used for tracking offset
    private integer blockSize =5;//for setting size of page
   
    //in this constructor we are setting values to boolean values
    public Acc_con_Opp_Details()
    {
    flag1=true;
    flag2=false;
    flag3=false;
        totalRecs = [select count() from Account];//returns total no.of account records 
       getactwrap();//calling getactwrap method.
    }
    //this method displays first five records
    public void beginning()
    {
        oppbox=false;
        conbox=false;
        index = 0;
        getactwrap();
    }
    //this method displays prevoius records
     public void previous()
    {
        oppbox=false;
        conbox=false;
        index = index-blockSize;
        getactwrap();
    }
    //this method displays next records
   public void next()
    {
        oppbox=false;
        conbox=false;
        index = index+blockSize;
        getactwrap();
    }
    //this method displays last remaining records
 public void end()
    {
        oppbox=false;
        conbox=false;
        index = totalrecs - math.mod(totalRecs,blockSize);
        getactwrap();
    }  
    //this variable is used to enable or disable first and previous buttons
 public boolean prev{get
    {
        if(index == 0)
        return true;
        else
        return false;
    }  set;}
    //this variable is used to enable or disable next and last buttons
 public boolean nxt{get
    {
        if((index + blockSize) > totalRecs)
        return true;
        else
        return false;
    }   set;}
    //used to display opportunities and contacts w.r.t selected accounts
    public void  submit()
    {
        flag1=false;
        acts=new list<Account>();
        for(accountwrapper aw:actwrap)
           {
            if(aw.acflag){
                acts.add(aw.acc);
           }
    }
        
        //if we select contact check box,then it displays contacts for selected accounts 
      if(conbox)
      {
      
              snts=[select id,lastName,Department,account.name from contact where accountid IN:acts];
              if(snts.size()>0)
              {
              flag3=true;
              }
              else
              {
              ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'contact records are not found for selected Accounts.'));
              }
         } 
        //if we select opportunity check box,then it displays opportunities for selected accounts
      if(oppbox)
        {
        
            
      opts=[select id,name,stageName,leadsource,account.name from opportunity where accountId IN:acts];
      if(opts.size() >0)
      {
      flag2=true;
      }
      else
       {
       ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'opportunity records are not found for selected Accounts.'));
       }
            } 
    }
   //it hides contacts and dispalys opportunitites on uncheck of contact check box
    public void Hideandshowopp()
    {
     
    if(oppbox==true)
    {
     flag2=true;
    }
    else
    {
     flag2=false;
    }
         
    }
   //  it hides opportunities and dispalys contacts on uncheck of opportunities check box 
     public void HideandshowCon()
    {
    if(conbox==true)
    {
     flag3=true;
    }
    else
    {
     flag3=false;
    }
         
    }
    
    //This method uses a simple SOQL query to return a List of Accounts
     public void getactwrap(){
         accounts = Database.Query('SELECT id,Name,phone FROM Account LIMIT :blockSize OFFSET :index');
         actwrap=new list<accountwrapper>();
       // As each Account is processed we create a new accountwrapper object and add it to the wrapper class(accountwrapper) list.
         for(account a:accounts)
        {
            actwrap.add(new accountwrapper(a));
        }
    }
    // this method  uses dml operation to edit the existing opportunities values or to insert new oppt values
    public void saveopps()
    {
        list<opportunity> opps=new list<opportunity>();
        opps.addAll(opts);
        upsert opps;
    }
    //his method  uses dml operation to edit the existing contact values or to insert new contact values
    public void savecons()
    {
       cnts = new list<contact>();
        cnts.addall(snts);
        upsert cnts;
    }
 //This is wrapper class which is collection of other class instances
  //here  wrapper class contains both the standard salesforce object Account and a Boolean value acflag   
 public class accountwrapper{
        public account acc{set;get;}
        public boolean acflag{set;get;}
             //In this contructor When we create a new accountwrapper object we pass a Account that is set to the acc property.
             // We also set the boolean value to false
        public accountwrapper(account a){
            acc=a;
            acflag=false;
        }
        
    }

}

vf page
----------
<apex:page controller="Acc_con_Opp_Details" showHeader="false" docType="html-5.0">
<apex:form >

    <!--This block dispalying account record details-->
    <apex:pageblock rendered="true">
    <apex:pageMessages ></apex:pageMessages>
    <apex:pageblocktable value="{!actwrap}" var="a">
        <apex:column >
    <apex:facet name="header" >Select</apex:facet>
             <apex:inputCheckbox value="{!a.acflag}"/>
        </apex:column>
        <!-- displays id,name and phone number for accounts-->
        <apex:column value="{!a.acc.id}"/>
        <apex:column value="{!a.acc.name}"/>
        <apex:column value="{!a.acc.phone}"/>
         </apex:pageblocktable>
        <!-- this buttons are used to paginate account records-->
        <apex:pageblockButtons >
            <!--displays first five records-->
            <apex:commandButton value="first"  action="{!beginning}" disabled="{!prev}"/>
            <!--displays previous records-->
            <apex:commandButton value="previous"  action="{!previous}" disabled="{!prev}"/>
             <!--displays previous  next records-->
            <apex:commandButton value="next"  action="{!next}" disabled="{!nxt}"/>
            <!-- displays last records-->
            <apex:commandButton value="last"  action="{!end}" disabled="{!nxt}"/>                                    
        </apex:pageblockButtons>
         <!-- check boxs for opportunities and contacts-->
        
     <center>  <apex:inputCheckbox value="{!oppbox}">
     <apex:actionSupport event="onchange" action="{!Hideandshowopp}"  rerender="block"/>
     </apex:inputCheckbox>Opportunities&nbsp;&nbsp;&nbsp;
         <apex:inputCheckbox value="{!conbox}">
         <apex:actionSupport event="onchange" action="{!HideandshowCon}" rerender="block"/>
         </apex:inputCheckbox>Contacts&nbsp;&nbsp;&nbsp;
        <apex:commandButton value="submit" action="{!submit}"/>
       </center>
    </apex:pageblock>
    <!--this block displays opportunity details-->
    <apex:pageblock rendered="{!flag2}" id="block" >
      
   <apex:pageblocktable value="{!opts}" var="o">
        
        <apex:column >
             <apex:facet name="header">Opportunity Id</apex:facet>
            <apex:commandlink value="{!o.id}" Action="{!URLFOR($Action.opportunity.edit,o.Id)}"/>
        </apex:column>
        <apex:column value="{!o.account.name}" />
        <apex:column >
            <apex:facet name="header">Opportunity Name</apex:facet>
       <apex:inputtext value="{!o.name}" />
            </apex:column>
        <apex:column >
           <apex:facet name="header">Opportunity Stage</apex:facet> 
       <apex:inputtext value="{!o.stagename}"/>
        </apex:column>
       <apex:column >
         <apex:facet name="header">Opportunity Leadsource</apex:facet> 
        </apex:column>
        </apex:pageblocktable>
        <apex:commandButton value="Save Opportunities" action="{!saveopps}"/>
    </apex:pageblock>
    <!--this block is used for displaying contact details -->
     <apex:pageblock rendered="{!flag3}">
         
     <apex:pageblocktable value="{!snts}" var="c">
        <apex:column >
            <apex:facet name="header">Contact Id</apex:facet>
            <apex:commandlink value="{!c}" Action="{!URLFOR($Action.contact.edit,c)}"/>
        </apex:column>
         <apex:column value="{!c.account.name}"/>
        <apex:column >
             <apex:facet name="header">Contact Lastname</apex:facet>
            <apex:inputtext value="{!c.lastname}"/>
        </apex:column>
        <apex:column >
        <apex:facet name="header">Contact Department</apex:facet>
            <apex:inputtext value="{!c.Department}"/>
        </apex:column>
        </apex:pageblocktable>
         <apex:commandButton value="Save Contacts" action="{!savecons}"/>
    </apex:pageblock>
   
    </apex:form>
</apex:page>
==============================================================================
 
Best Answer chosen by anu deep 6
Siva@51Siva@51
Hi Anudeep,
Here you go
Apex Class
===================================================================
public class Acc_con_Opp_Details
{
    //list of collection of the wrapper class object
    public list<accountwrapper> actwrap           {set;get;}
    //list of collection of Account,contact and opportunity objects
    public list<Account>        accounts          {set;get;}
    public list<Account>        acts              {set;get;}
    public list<opportunity>    opts              {set;get;}
    public list<opportunity>    sopts             {set;get;}
    public list<contact>        cnts              {set;get;} 
    public list<contact>        snts              {set;get;}
    public boolean oppbox                         {set;get;}//used as check box for opportunity 
    public boolean conbox                         {set;get;}//used as check box for contact
    public boolean flag1                          {set;get;}//used in account page block  
    public boolean flag2                          {set;get;}//used in contact page block 
    public boolean flag3                          {set;get;}//used in opportunity page block
    public boolean checkallflag                   {set;get;}//used for header check box
    public Boolean oppError                       {set;get;}
    public Boolean conError                       {set;get;}
    public list<String> AlphaList                 {get; set;}
    public String AlphaFilter                     {get; set;}
    private String Query;
    //this variables are used for pagination purpose
    private integer totalRecs = 0;//stores no.of total records   
    private integer index = 0;//used for tracking offset
    private integer blockSize =5;//for setting size of page
    private String sortDirection = 'ASC';
    private String sortExp = 'Name';
    public Map<String, String> mapAlpha{get; set;}
 
    //in this constructor we are setting values to boolean values
    public Acc_con_Opp_Details()
    {
    flag1=true;
    flag2=false;
    flag3=false;
    oppError=false;
    conError=false;
    checkallflag = false;
    totalRecs = [select count() from Account];//returns total no.of account records 
    getactwrap();//calling getactwrap method.
    AlphaList = new list<String> {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'Other', 'All'};
    if (apexpages.currentpage().getparameters().get('alpha') == null) {
        AlphaFilter = 'All';
    } else {
        AlphaFilter = apexpages.currentpage().getparameters().get('alpha');
    }
    }
    public String sortExpression
    {
      get
      {
         return sortExp;
      }
      set
      {
        //if the column is clicked on then switch between Ascending and Descending modes
        if (value == sortExp)
          sortDirection = (sortDirection == 'ASC')? 'DESC' : 'ASC';
        else
          sortDirection = 'ASC';
          sortExp = value;
      }
    }

    public String getSortDirection()
    {
       //if not column is selected 
       if (sortExpression == null || sortExpression == '')
           return 'ASC';
       else
          return sortDirection;
    }

    public void setSortDirection(String value)
    {  
        sortDirection = value;
    }
    //this method displays first five records
    public void beginning()
    {    
        flag2 = false;
        flag3 = false;
        oppbox=false;
        conbox=false;
        checkallflag=false;
        index = 0;
        getactwrap();
    }
    //this method displays prevoius records
     public void previous()
    {    
        flag2 = false;
        flag3 = false;
        oppbox=false;
        conbox=false;
        checkallflag=false;
        index = index-blockSize;
        getactwrap();
    }
    //this method displays next records
   public void next()
    {    
        flag2 = false;
        flag3 = false;
        oppbox=false;
        conbox=false;
        checkallflag=false;
        index = index+blockSize;
        getactwrap();
    }
    //this method displays last remaining records
 public void end()
    {    
        flag2 = false;
        flag3 = false;
        oppbox=false;
        conbox=false;
        checkallflag=false;
        index = totalrecs - math.mod(totalRecs,blockSize);
        getactwrap();
    }  
    //this variable is used to enable or disable first and previous buttons
 public boolean prev{get
    {
        if(index == 0)
        return true;
        else
        return false;
    }  set;}
    //this variable is used to enable or disable next and last buttons
 public boolean nxt{get
    {
        if((index + blockSize) > totalRecs)
        return true;
        else
        return false;
    }   set;}
    //used to display opportunities and contacts w.r.t selected accounts
    public void  submit()
    {
        flag1=false;
        acts=new list<Account>();
        List<Boolean> acflagList = new List<Boolean>();
        for(accountwrapper aw:actwrap)
           {
            if(aw.acflag){
                acts.add(aw.acc);
                acflagList.add(aw.acflag);
           } 
        }
        if(acflagList.isEmpty()) {
           oppbox=false;
           conbox=false;
           flag2=false;
           flag3=false;
           oppError=false;
           conError=false;
        }
        
        //if we select contact check box,then it displays contacts for selected accounts 
      if(conbox)
      {
      
              snts=[select id,lastName,Department,account.name from contact where accountid IN:acts];
              if(snts.size()>0)
              {
                  flag3=true;
                  conError=false;
              }
              else
              {
                  for(accountwrapper aw : actwrap) {
                      if(aw.acflag) {
                          flag3=true;
                          conError = true;
                      }
                          //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'contact records are not found for selected Accounts.'));
                    }
              }
         } else {
             flag3 = false;
         }
        //if we select opportunity check box,then it displays opportunities for selected accounts
      if(oppbox)
        {
              opts=[select id,name,stageName,leadsource,account.name from opportunity where accountId IN:acts];
              if(opts.size() >0)
              {
                  flag2=true;
                  oppError=false;
              }
              else       
              {    
                    for(accountwrapper aw : actwrap) {
                      if(aw.acflag) {
                          flag2=true;
                          oppError = true;
                      }
                          //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'opportunity records are not found for selected Accounts.'));
                    }
              }
        } else {
            flag2 = false;
        }
    }
   //it hides contacts and dispalys opportunitites on uncheck of contact check box
   //This method uses a simple SOQL query to return a List of Accounts
    public void getactwrap() {
        String QueryIf = '';
        string sortFullExp = sortExpression  + ' ' + sortDirection;
        if (AlphaFilter == null || AlphaFilter.trim().length() == 0) {
            AlphaFilter = 'All';
        }
        
        Query = 'SELECT Id, Name, phone ' + ' FROM Account'; 
        
        if (AlphaFilter == 'Other') {
            QueryIf = QueryFor(QueryIf, '(' + 'Name' + ' < \'A\' OR ' + 
                                    'Name' + ' > \'Z\') AND (NOT ' + 
                                    'Name' + ' LIKE \'Z%\') ');
        } else if (AlphaFilter != 'All') {
            QueryIf = QueryFor(QueryIf, '(' + 'Name' + ' LIKE \'' + String.escapeSingleQuotes(AlphaFilter) + '%\')' );
        }
        
        Query += QueryIf;
        Query += ' ORDER BY ' + sortFullExp + ' LIMIT : blockSize OFFSET : index';
        accounts = Database.Query(Query);
        actwrap=new list<accountwrapper>();
       // As each Account is processed we create a new accountwrapper object and add it to the wrapper class(accountwrapper) list.
         for(account a:accounts)
        {
            actwrap.add(new accountwrapper(a));
        }
        flag2=false;
        flag3=false;
        oppbox=false;
        conbox=false;
        checkallflag=false;
    }
    public String QueryFor(String Q, String C) {
        if (Q == '') {
            return ' WHERE ' + C;
        } else {
            return Q + ' AND ' + C;
        }
    }
    public void Hideandshowopp()
    {
     
        if(oppbox)
          {     
              submit();
          } else {
              flag2 = false;
          }
         
    }
   //  it hides opportunities and dispalys contacts on uncheck of opportunities check box 
     public void HideandshowCon()
    {
        if(conbox)
         {    
              submit();
          } else {
              flag3 = false;
          }
         
    }
   
    public void Hideandshowoppcon() {
        Hideandshowopp();
        Hideandshowcon();
    }
    
    
    // this method  uses dml operation to edit the existing opportunities values or to insert new oppt values
    public void saveopps()
    {
        list<opportunity> opps=new list<opportunity>();
        opps.addAll(opts);
        upsert opps;
    }
    //his method  uses dml operation to edit the existing contact values or to insert new contact values
    public void savecons()
    {
       cnts = new list<contact>();
        cnts.addall(snts);
        upsert cnts;
    }
 //This is wrapper class which is collection of other class instances
  //here  wrapper class contains both the standard salesforce object Account and a Boolean value acflag   
 public class accountwrapper{
        public account acc{set;get;}
        public boolean acflag{set;get;}
             //In this contructor When we create a new accountwrapper object we pass a Account that is set to the acc property.
             // We also set the boolean value to false
        public accountwrapper(account a){
            acc=a;
            acflag=false;
        }
        
    }

}
 

All Answers

Siva@51Siva@51
Try this
====================================================================================================
Apex class
-----------------
public class Acc_con_Opp_Details
{
    
    //list of collection of the wrapper class object
    public list<accountwrapper> actwrap           {set;get;}
    //list of collection of Account,contact and opportunity objects
    public list<Account>        accounts          {set;get;}
    public list<Account>        acts              {set;get;}
    public list<opportunity>    opts              {set;get;}
    public list<opportunity>    sopts             {set;get;}
    public list<contact>        cnts              {set;get;} 
    public list<contact>        snts              {set;get;}
    public boolean oppbox                         {set;get;}//used as check box for opportunity 
    public boolean conbox                         {set;get;}//used as check box for contact
    public boolean flag1                          {set;get;}//used in account page block  
    public boolean flag2                          {set;get;}//used in contact page block 
    public boolean flag3                          {set;get;}//used in opportunity page block
    //this variables are used for pagination purpose
    private integer totalRecs = 0;//stores no.of total records   
    private integer index = 0;//used for tracking offset
    private integer blockSize =5;//for setting size of page
   
    //in this constructor we are setting values to boolean values
    public Acc_con_Opp_Details()
    {
    flag1=true;
    flag2=false;
    flag3=false;
        totalRecs = [select count() from Account];//returns total no.of account records 
       getactwrap();//calling getactwrap method.
    }
    //this method displays first five records
    public void beginning()
    {
        oppbox=false;
        conbox=false;
        index = 0;
        getactwrap();
    }
    //this method displays prevoius records
     public void previous()
    {
        oppbox=false;
        conbox=false;
        index = index-blockSize;
        getactwrap();
    }
    //this method displays next records
   public void next()
    {
        oppbox=false;
        conbox=false;
        index = index+blockSize;
        getactwrap();
    }
    //this method displays last remaining records
 public void end()
    {
        oppbox=false;
        conbox=false;
        index = totalrecs - math.mod(totalRecs,blockSize);
        getactwrap();
    }  
    //this variable is used to enable or disable first and previous buttons
 public boolean prev{get
    {
        if(index == 0)
        return true;
        else
        return false;
    }  set;}
    //this variable is used to enable or disable next and last buttons
 public boolean nxt{get
    {
        if((index + blockSize) > totalRecs)
        return true;
        else
        return false;
    }   set;}
    //used to display opportunities and contacts w.r.t selected accounts
    public void  submit()
    {
        flag1=false;
        acts=new list<Account>();
        for(accountwrapper aw:actwrap)
           {
            if(aw.acflag){
                acts.add(aw.acc);
           }
    }
        
        //if we select contact check box,then it displays contacts for selected accounts 
      if(conbox)
      {
      
              snts=[select id,lastName,Department,account.name from contact where accountid IN:acts];
              if(snts.size()>0)
              {
              flag3=true;
              }
              else
              {
              ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'contact records are not found for selected Accounts.'));
              }
         } 
        //if we select opportunity check box,then it displays opportunities for selected accounts
      if(oppbox)
        {
        
            
      opts=[select id,name,stageName,leadsource,account.name from opportunity where accountId IN:acts];
      if(opts.size() >0)
      {
      flag2=true;
      }
      else
       {
       ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'opportunity records are not found for selected Accounts.'));
       }
            } 
    }
   //it hides contacts and dispalys opportunitites on uncheck of contact check box
    public void Hideandshowopp()
    {
     
    if(oppbox==true)
    {
     flag2=true;
     submit();
    }
    else
    {
     flag2=false;
    }
         
    }
   //  it hides opportunities and dispalys contacts on uncheck of opportunities check box 
     public void HideandshowCon()
    {
    if(conbox==true)
    {
     flag3=true;
     submit();
    }
    else
    {
     flag3=false;
    }
         
    }
    
    //This method uses a simple SOQL query to return a List of Accounts
     public void getactwrap(){
         accounts = Database.Query('SELECT id,Name,phone FROM Account LIMIT :blockSize OFFSET :index');
         actwrap=new list<accountwrapper>();
       // As each Account is processed we create a new accountwrapper object and add it to the wrapper class(accountwrapper) list.
         for(account a:accounts)
        {
            actwrap.add(new accountwrapper(a));
        }
    }
    // this method  uses dml operation to edit the existing opportunities values or to insert new oppt values
    public void saveopps()
    {
        list<opportunity> opps=new list<opportunity>();
        opps.addAll(opts);
        upsert opps;
    }
    //his method  uses dml operation to edit the existing contact values or to insert new contact values
    public void savecons()
    {
       cnts = new list<contact>();
        cnts.addall(snts);
        upsert cnts;
    }
 //This is wrapper class which is collection of other class instances
  //here  wrapper class contains both the standard salesforce object Account and a Boolean value acflag   
 public class accountwrapper{
        public account acc{set;get;}
        public boolean acflag{set;get;}
             //In this contructor When we create a new accountwrapper object we pass a Account that is set to the acc property.
             // We also set the boolean value to false
        public accountwrapper(account a){
            acc=a;
            acflag=false;
        }
        
    }

}


Page
----------------------------------------

<apex:page controller="Acc_con_Opp_Details" showHeader="false" docType="html-5.0">
<apex:form >

    <!--This block dispalying account record details-->
    <apex:pageblock rendered="true">
    <apex:pageMessages ></apex:pageMessages>
    <apex:pageblocktable value="{!actwrap}" var="a">
        <apex:column >
    <apex:facet name="header" >Select</apex:facet>
             <apex:inputCheckbox value="{!a.acflag}"/>
        </apex:column>
        <!-- displays id,name and phone number for accounts-->
        <apex:column value="{!a.acc.id}"/>
        <apex:column value="{!a.acc.name}"/>
        <apex:column value="{!a.acc.phone}"/>
         </apex:pageblocktable>
        <!-- this buttons are used to paginate account records-->
        <apex:pageblockButtons >
            <!--displays first five records-->
            <apex:commandButton value="first"  action="{!beginning}" disabled="{!prev}"/>
            <!--displays previous records-->
            <apex:commandButton value="previous"  action="{!previous}" disabled="{!prev}"/>
             <!--displays previous  next records-->
            <apex:commandButton value="next"  action="{!next}" disabled="{!nxt}"/>
            <!-- displays last records-->
            <apex:commandButton value="last"  action="{!end}" disabled="{!nxt}"/>                                    
        </apex:pageblockButtons>
         <!-- check boxs for opportunities and contacts-->
        
     <center>  <apex:inputCheckbox value="{!oppbox}">
     <apex:actionSupport event="onchange" action="{!Hideandshowopp}"/>
     </apex:inputCheckbox>Opportunities&nbsp;&nbsp;&nbsp;
         <apex:inputCheckbox value="{!conbox}">
         <apex:actionSupport event="onchange" action="{!HideandshowCon}"/>
         </apex:inputCheckbox>Contacts&nbsp;&nbsp;&nbsp;
        <apex:commandButton value="submit" action="{!submit}"/>
       </center>
    </apex:pageblock>
    <!--this block displays opportunity details-->
    <apex:pageblock rendered="{!flag2}" id="block" >
      
   <apex:pageblocktable value="{!opts}" var="o">
        
        <apex:column >
             <apex:facet name="header">Opportunity Id</apex:facet>
            <apex:commandlink value="{!o.id}" Action="{!URLFOR($Action.opportunity.edit,o.Id)}"/>
        </apex:column>
        <apex:column value="{!o.account.name}" />
        <apex:column >
            <apex:facet name="header">Opportunity Name</apex:facet>
       <apex:inputtext value="{!o.name}" />
            </apex:column>
        <apex:column >
           <apex:facet name="header">Opportunity Stage</apex:facet> 
       <apex:inputtext value="{!o.stagename}"/>
        </apex:column>
       <apex:column >
         <apex:facet name="header">Opportunity Leadsource</apex:facet> 
        </apex:column>
        </apex:pageblocktable>
        <apex:commandButton value="Save Opportunities" action="{!saveopps}"/>
    </apex:pageblock>
    <!--this block is used for displaying contact details -->
     <apex:pageblock rendered="{!flag3}">
         
     <apex:pageblocktable value="{!snts}" var="c">
        <apex:column >
            <apex:facet name="header">Contact Id</apex:facet>
            <apex:commandlink value="{!c}" Action="{!URLFOR($Action.contact.edit,c)}"/>
        </apex:column>
         <apex:column value="{!c.account.name}"/>
        <apex:column >
             <apex:facet name="header">Contact Lastname</apex:facet>
            <apex:inputtext value="{!c.lastname}"/>
        </apex:column>
        <apex:column >
        <apex:facet name="header">Contact Department</apex:facet>
            <apex:inputtext value="{!c.Department}"/>
        </apex:column>
        </apex:pageblocktable>
         <apex:commandButton value="Save Contacts" action="{!savecons}"/>
    </apex:pageblock>
   
    </apex:form>
</apex:page>

=========================================================================================================

Please mark this as best answer if your functionality is achieved.
Thanks :)
anu deep 6anu deep 6
Hi siva,
 Greatly appreciating your response.Thanks for helping me to achieve required functionality.And Please help me to fix few more bugs in above code.

current functionality:
==============
1.)If I deselet account records still opportunities and contact records are displaying.

required functionalitiy:
===============
1.)If I deselect account records related opportunities and contact records need to be disappear.
2.)If I select account records,related opportunities and contact records need to be display.

And also plese fix following bugs,

-->Even though I didn't select any account and selected opportunites and clicked on submit it is showing error message. If I select any account and select opportunites check box and click on submit, then only it should show the error message.

-->I need to display a blank table with "No Opportunites Found" message in case the selected accounts doesn't have any opportunities.
        The same is the case with contacts.
-->If click on next button  in accounts table, still It is displaying opportunities and contacts even though I didn't select anything.
       please help me to fix above bugs. 
 
Salesforce####Salesforce####
hello @siva51 : 

it working can you ley us know , what s the peice of code you changed above , can you explain us how to write which will be a good thing for us to remeber . 

@Thanks in adv
Siva@51Siva@51
Hello @Salesforce####
  • I have removed Rerender from input checkbox onchange events in page. Please see below link https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_actionSupport.htm
  • Added Submit() in  Hideandshowopp() and  Hideandshowcon() of controller.
anu deep 6anu deep 6
hello siva

The code provided by you is working perfectly.Please help me to achive following functionalities in above code

current functionality:
==============
1.)If I deselet account records still opportunities and contact records are displaying.

required functionalitiy:
===============
1.)If I deselect account records related opportunities and contact records need to be disappear.
2.)If I select account records,related opportunities and contact records need to be display.

And also plese fix following bugs,
========================

-->Even though I didn't select any account and selected opportunites and clicked on submit it is showing error message. If I select any account and select opportunites check box and click on submit, then only it should show the error message.

-->I need to display a blank table with "No Opportunites Found" message in case the selected accounts doesn't have any opportunities.
        The same is the case with contacts.
-->If click on next button  in accounts table, still It is displaying opportunities and contacts even though I didn't select anything.
       please help me to fix above bugs.
 
Siva@51Siva@51
Hello Anudeep,

Apex Class
=========================================================================================================
public class Acc_con_Opp_Details
{
    //list of collection of the wrapper class object
    public list<accountwrapper> actwrap           {set;get;}
    //list of collection of Account,contact and opportunity objects
    public list<Account>        accounts          {set;get;}
    public list<Account>        acts              {set;get;}
    public list<opportunity>    opts              {set;get;}
    public list<opportunity>    sopts             {set;get;}
    public list<contact>        cnts              {set;get;} 
    public list<contact>        snts              {set;get;}
    public boolean oppbox                         {set;get;}//used as check box for opportunity 
    public boolean conbox                         {set;get;}//used as check box for contact
    public boolean flag1                          {set;get;}//used in account page block  
    public boolean flag2                          {set;get;}//used in contact page block 
    public boolean flag3                          {set;get;}//used in opportunity page block
    //this variables are used for pagination purpose
    private integer totalRecs = 0;//stores no.of total records   
    private integer index = 0;//used for tracking offset
    private integer blockSize =5;//for setting size of page
    
   
    //in this constructor we are setting values to boolean values
    public Acc_con_Opp_Details()
    {
    flag1=true;
    flag2=false;
    flag3=false;
        totalRecs = [select count() from Account];//returns total no.of account records 
       getactwrap();//calling getactwrap method.
    }
    //this method displays first five records
    public void beginning()
    {    
        flag2 = false;
        flag3 = false;
        oppbox=false;
        conbox=false;
        index = 0;
        getactwrap();
    }
    //this method displays prevoius records
     public void previous()
    {    
        flag2 = false;
        flag3 = false;
        oppbox=false;
        conbox=false;
        index = index-blockSize;
        getactwrap();
    }
    //this method displays next records
   public void next()
    {    
        flag2 = false;
        flag3 = false;
        oppbox=false;
        conbox=false;
        index = index+blockSize;
        getactwrap();
    }
    //this method displays last remaining records
 public void end()
    {    
        flag2 = false;
        flag3 = false;
        oppbox=false;
        conbox=false;
        index = totalrecs - math.mod(totalRecs,blockSize);
        getactwrap();
    }  
    //this variable is used to enable or disable first and previous buttons
 public boolean prev{get
    {
        if(index == 0)
        return true;
        else
        return false;
    }  set;}
    //this variable is used to enable or disable next and last buttons
 public boolean nxt{get
    {
        if((index + blockSize) > totalRecs)
        return true;
        else
        return false;
    }   set;}
    //used to display opportunities and contacts w.r.t selected accounts
    public void  submit()
    {
        flag1=false;
        acts=new list<Account>();
        for(accountwrapper aw:actwrap)
           {
            if(aw.acflag){
                acts.add(aw.acc);
           }
    }
        
        //if we select contact check box,then it displays contacts for selected accounts 
      if(conbox)
      {
      
              snts=[select id,lastName,Department,account.name from contact where accountid IN:acts];
              if(snts.size()>0)
              {
                  flag3=true;
              }
              else
              {
                  for(accountwrapper aw : actwrap) {
                      if(aw.acflag)
                          ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'contact records are not found for selected Accounts.'));
                    }
              }
         } else {
             flag3 = false;
         }
        //if we select opportunity check box,then it displays opportunities for selected accounts
      if(oppbox)
        {
              opts=[select id,name,stageName,leadsource,account.name from opportunity where accountId IN:acts];
              if(opts.size() >0)
              {
                  flag2=true;
              }
              else       
              {
                    for(accountwrapper aw : actwrap) {
                      if(aw.acflag)
                          ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'opportunity records are not found for selected Accounts.'));
                    }
              }
        } else {
            flag2 = false;
        }
    }
   //it hides contacts and dispalys opportunitites on uncheck of contact check box
   
    public void Hideandshowopp()
    {
     
        if(oppbox)
          {     
              submit();
          } else {
              flag2 = false;
          }
         
    }
   //  it hides opportunities and dispalys contacts on uncheck of opportunities check box 
     public void HideandshowCon()
    {
        if(conbox)
         {    
              submit();
          } else {
              flag3 = false;
          }
         
    }
   
    public void Hideandshowoppcon() {
        Hideandshowopp();
        Hideandshowcon();
    }
    
    
    //This method uses a simple SOQL query to return a List of Accounts
     public void getactwrap() {
         accounts = Database.Query('SELECT id,Name,phone FROM Account LIMIT :blockSize OFFSET :index');
         actwrap=new list<accountwrapper>();
       // As each Account is processed we create a new accountwrapper object and add it to the wrapper class(accountwrapper) list.
         for(account a:accounts)
        {
            actwrap.add(new accountwrapper(a));
        }
    }
    // this method  uses dml operation to edit the existing opportunities values or to insert new oppt values
    public void saveopps()
    {
        list<opportunity> opps=new list<opportunity>();
        opps.addAll(opts);
        upsert opps;
    }
    //his method  uses dml operation to edit the existing contact values or to insert new contact values
    public void savecons()
    {
       cnts = new list<contact>();
        cnts.addall(snts);
        upsert cnts;
    }
 //This is wrapper class which is collection of other class instances
  //here  wrapper class contains both the standard salesforce object Account and a Boolean value acflag   
 public class accountwrapper{
        public account acc{set;get;}
        public boolean acflag{set;get;}
             //In this contructor When we create a new accountwrapper object we pass a Account that is set to the acc property.
             // We also set the boolean value to false
        public accountwrapper(account a){
            acc=a;
            acflag=false;
        }
        
    }

}

==============================================================================================
Page
==============================================================================================
<apex:page controller="Acc_con_Opp_Details" showHeader="false" docType="html-5.0">
<apex:form >

    <!--This block dispalying account record details-->
    <apex:pageblock rendered="true">
    <apex:pageMessages ></apex:pageMessages>
    <apex:pageblocktable value="{!actwrap}" var="a">
        <apex:column >
    <apex:facet name="header" >Select</apex:facet>
             <apex:inputCheckbox value="{!a.acflag}">
                 <apex:actionSupport event="onchange" action="{!Hideandshowoppcon}"/>
             </apex:inputCheckbox>
        </apex:column>
        <!-- displays id,name and phone number for accounts-->
        <apex:column value="{!a.acc.id}"/>
        <apex:column value="{!a.acc.name}"/>
        <apex:column value="{!a.acc.phone}"/>
         </apex:pageblocktable>
        <!-- this buttons are used to paginate account records-->
        <apex:pageblockButtons >
            <!--displays first five records-->
            <apex:commandButton value="first"  action="{!beginning}" disabled="{!prev}"/>
            <!--displays previous records-->
            <apex:commandButton value="previous"  action="{!previous}" disabled="{!prev}"/>
             <!--displays previous  next records-->
            <apex:commandButton value="next"  action="{!next}" disabled="{!nxt}"/>
            <!-- displays last records-->
            <apex:commandButton value="last"  action="{!end}" disabled="{!nxt}"/>                                    
        </apex:pageblockButtons>
         <!-- check boxs for opportunities and contacts-->
        
     <center>  <apex:inputCheckbox value="{!oppbox}">
     <apex:actionSupport event="onchange" action="{!Hideandshowopp}"/>
     </apex:inputCheckbox>Opportunities&nbsp;&nbsp;&nbsp;
         <apex:inputCheckbox value="{!conbox}">
         <apex:actionSupport event="onchange" action="{!HideandshowCon}"/>
         </apex:inputCheckbox>Contacts&nbsp;&nbsp;&nbsp;
        <apex:commandButton value="submit" action="{!submit}"/>
       </center>
    </apex:pageblock>
    <!--this block displays opportunity details-->
    <apex:pageblock rendered="{!flag2}" id="block" >
      
   <apex:pageblocktable value="{!opts}" var="o">
        
        <apex:column >
             <apex:facet name="header">Opportunity Id</apex:facet>
            <apex:commandlink value="{!o.id}" Action="{!URLFOR($Action.opportunity.edit,o.Id)}"/>
        </apex:column>
        <apex:column value="{!o.account.name}" />
        <apex:column >
            <apex:facet name="header">Opportunity Name</apex:facet>
       <apex:inputtext value="{!o.name}" />
            </apex:column>
        <apex:column >
           <apex:facet name="header">Opportunity Stage</apex:facet> 
       <apex:inputtext value="{!o.stagename}"/>
        </apex:column>
       <apex:column >
         <apex:facet name="header">Opportunity Leadsource</apex:facet> 
        </apex:column>
        </apex:pageblocktable>
        <apex:commandButton value="Save Opportunities" action="{!saveopps}"/>
    </apex:pageblock>
    <!--this block is used for displaying contact details -->
     <apex:pageblock rendered="{!flag3}">
         
     <apex:pageblocktable value="{!snts}" var="c">
        <apex:column >
            <apex:facet name="header">Contact Id</apex:facet>
            <apex:commandlink value="{!c}" Action="{!URLFOR($Action.contact.edit,c)}"/>
        </apex:column>
         <apex:column value="{!c.account.name}"/>
        <apex:column >
             <apex:facet name="header">Contact Lastname</apex:facet>
            <apex:inputtext value="{!c.lastname}"/>
        </apex:column>
        <apex:column >
        <apex:facet name="header">Contact Department</apex:facet>
            <apex:inputtext value="{!c.Department}"/>
        </apex:column>
        </apex:pageblocktable>
         <apex:commandButton value="Save Contacts" action="{!savecons}"/>
    </apex:pageblock>
   
    </apex:form>
</apex:page>

=================================================================================================

Hope this resolves your bugs.

Thanks :)
anu deep 6anu deep 6
Hi siva,

Many many thanks.It was working according to requirement.But error messages are displaying at top of account table.what I am expecting is

1.)In case the selected accounts doesn't have any opportunities.,error message should display in  blank table under account table with "No Opportunites Found" message.
2.)In case the selected accounts doesn't have any contacts.,error message should display in  blank table under account table with "No contacts Found" message.


 
Siva@51Siva@51
Hi Anudeep,

Apex Class
========================================================================================================
public class Acc_con_Opp_Details
{
    //list of collection of the wrapper class object
    public list<accountwrapper> actwrap           {set;get;}
    //list of collection of Account,contact and opportunity objects
    public list<Account>        accounts          {set;get;}
    public list<Account>        acts              {set;get;}
    public list<opportunity>    opts              {set;get;}
    public list<opportunity>    sopts             {set;get;}
    public list<contact>        cnts              {set;get;} 
    public list<contact>        snts              {set;get;}
    public boolean oppbox                         {set;get;}//used as check box for opportunity 
    public boolean conbox                         {set;get;}//used as check box for contact
    public boolean flag1                          {set;get;}//used in account page block  
    public boolean flag2                          {set;get;}//used in contact page block 
    public boolean flag3                          {set;get;}//used in opportunity page block
    public Boolean oppError                       {set;get;}
    public Boolean conError                       {set;get;}
    //this variables are used for pagination purpose
    private integer totalRecs = 0;//stores no.of total records   
    private integer index = 0;//used for tracking offset
    private integer blockSize =5;//for setting size of page
    
   
    //in this constructor we are setting values to boolean values
    public Acc_con_Opp_Details()
    {
    flag1=true;
    flag2=false;
    flag3=false;
    oppError=false;
    conError=false;
    totalRecs = [select count() from Account];//returns total no.of account records 
    getactwrap();//calling getactwrap method.
    }
    //this method displays first five records
    public void beginning()
    {    
        flag2 = false;
        flag3 = false;
        oppbox=false;
        conbox=false;
        index = 0;
        getactwrap();
    }
    //this method displays prevoius records
     public void previous()
    {    
        flag2 = false;
        flag3 = false;
        oppbox=false;
        conbox=false;
        index = index-blockSize;
        getactwrap();
    }
    //this method displays next records
   public void next()
    {    
        flag2 = false;
        flag3 = false;
        oppbox=false;
        conbox=false;
        index = index+blockSize;
        getactwrap();
    }
    //this method displays last remaining records
 public void end()
    {    
        flag2 = false;
        flag3 = false;
        oppbox=false;
        conbox=false;
        index = totalrecs - math.mod(totalRecs,blockSize);
        getactwrap();
    }  
    //this variable is used to enable or disable first and previous buttons
 public boolean prev{get
    {
        if(index == 0)
        return true;
        else
        return false;
    }  set;}
    //this variable is used to enable or disable next and last buttons
 public boolean nxt{get
    {
        if((index + blockSize) > totalRecs)
        return true;
        else
        return false;
    }   set;}
    //used to display opportunities and contacts w.r.t selected accounts
    public void  submit()
    {
        flag1=false;
        acts=new list<Account>();
        for(accountwrapper aw:actwrap)
           {
            if(aw.acflag){
                acts.add(aw.acc);
           }
    }
        
        //if we select contact check box,then it displays contacts for selected accounts 
      if(conbox)
      {
      
              snts=[select id,lastName,Department,account.name from contact where accountid IN:acts];
              if(snts.size()>0)
              {
                  flag3=true;
                  conError=false;
              }
              else
              {
                  for(accountwrapper aw : actwrap) {
                      if(aw.acflag)
                          conError = true;
                          //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'contact records are not found for selected Accounts.'));
                    }
              }
         } else {
             flag3 = false;
         }
        //if we select opportunity check box,then it displays opportunities for selected accounts
      if(oppbox)
        {
              opts=[select id,name,stageName,leadsource,account.name from opportunity where accountId IN:acts];
              if(opts.size() >0)
              {
                  flag2=true;
                  oppError=false;
              }
              else       
              {
                    for(accountwrapper aw : actwrap) {
                      if(aw.acflag)
                          oppError = true;
                          //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'opportunity records are not found for selected Accounts.'));
                    }
              }
        } else {
            flag2 = false;
        }
    }
   //it hides contacts and dispalys opportunitites on uncheck of contact check box
   
    public void Hideandshowopp()
    {
     
        if(oppbox)
          {     
              submit();
          } else {
              flag2 = false;
          }
         
    }
   //  it hides opportunities and dispalys contacts on uncheck of opportunities check box 
     public void HideandshowCon()
    {
        if(conbox)
         {    
              submit();
          } else {
              flag3 = false;
          }
         
    }
   
    public void Hideandshowoppcon() {
        Hideandshowopp();
        Hideandshowcon();
    }
    
    
    //This method uses a simple SOQL query to return a List of Accounts
     public void getactwrap() {
         accounts = Database.Query('SELECT id,Name,phone FROM Account LIMIT :blockSize OFFSET :index');
         actwrap=new list<accountwrapper>();
       // As each Account is processed we create a new accountwrapper object and add it to the wrapper class(accountwrapper) list.
         for(account a:accounts)
        {
            actwrap.add(new accountwrapper(a));
        }
    }
    // this method  uses dml operation to edit the existing opportunities values or to insert new oppt values
    public void saveopps()
    {
        list<opportunity> opps=new list<opportunity>();
        opps.addAll(opts);
        upsert opps;
    }
    //his method  uses dml operation to edit the existing contact values or to insert new contact values
    public void savecons()
    {
       cnts = new list<contact>();
        cnts.addall(snts);
        upsert cnts;
    }
 //This is wrapper class which is collection of other class instances
  //here  wrapper class contains both the standard salesforce object Account and a Boolean value acflag   
 public class accountwrapper{
        public account acc{set;get;}
        public boolean acflag{set;get;}
             //In this contructor When we create a new accountwrapper object we pass a Account that is set to the acc property.
             // We also set the boolean value to false
        public accountwrapper(account a){
            acc=a;
            acflag=false;
        }
        
    }

}

=====================================================================================================
Page
=======================================================================================================
<apex:page controller="Acc_con_Opp_Details" showHeader="false" docType="html-5.0">
<apex:form >

    <!--This block dispalying account record details-->
    <apex:pageblock rendered="true">
    <apex:pageMessages ></apex:pageMessages>
    <apex:pageblocktable value="{!actwrap}" var="a">
        <apex:column >
    <apex:facet name="header" >Select</apex:facet>
             <apex:inputCheckbox value="{!a.acflag}">
                 <apex:actionSupport event="onchange" action="{!Hideandshowoppcon}"/>
             </apex:inputCheckbox>
        </apex:column>
        <!-- displays id,name and phone number for accounts-->
        <apex:column value="{!a.acc.id}"/>
        <apex:column value="{!a.acc.name}"/>
        <apex:column value="{!a.acc.phone}"/>
         </apex:pageblocktable>
        <!-- this buttons are used to paginate account records-->
        <apex:pageblockButtons >
            <!--displays first five records-->
            <apex:commandButton value="first"  action="{!beginning}" disabled="{!prev}"/>
            <!--displays previous records-->
            <apex:commandButton value="previous"  action="{!previous}" disabled="{!prev}"/>
             <!--displays previous  next records-->
            <apex:commandButton value="next"  action="{!next}" disabled="{!nxt}"/>
            <!-- displays last records-->
            <apex:commandButton value="last"  action="{!end}" disabled="{!nxt}"/>                                    
        </apex:pageblockButtons>
         <!-- check boxs for opportunities and contacts-->
        
     <center>  <apex:inputCheckbox value="{!oppbox}">
     <apex:actionSupport event="onchange" action="{!Hideandshowopp}"/>
     </apex:inputCheckbox>Opportunities&nbsp;&nbsp;&nbsp;
         <apex:inputCheckbox value="{!conbox}">
         <apex:actionSupport event="onchange" action="{!HideandshowCon}"/>
         </apex:inputCheckbox>Contacts&nbsp;&nbsp;&nbsp;
        <apex:commandButton value="submit" action="{!submit}"/>
       </center>
    </apex:pageblock>
    <apex:pageMessage rendered="{!oppError}" severity="error" strength="1" summary="No Opportunites Found" /> 
    <apex:pageMessage rendered="{!conError}" severity="error" strength="1" summary="No Contacts Found" /> 
    <!--this block displays opportunity details-->
    <apex:pageblock rendered="{!flag2}" id="block" >
      
   <apex:pageblocktable value="{!opts}" var="o">
        
        <apex:column >
             <apex:facet name="header">Opportunity Id</apex:facet>
            <apex:commandlink value="{!o.id}" Action="{!URLFOR($Action.opportunity.edit,o.Id)}"/>
        </apex:column>
        <apex:column value="{!o.account.name}" />
        <apex:column >
            <apex:facet name="header">Opportunity Name</apex:facet>
       <apex:inputtext value="{!o.name}" />
            </apex:column>
        <apex:column >
           <apex:facet name="header">Opportunity Stage</apex:facet> 
       <apex:inputtext value="{!o.stagename}"/>
        </apex:column>
       <apex:column >
         <apex:facet name="header">Opportunity Leadsource</apex:facet> 
        </apex:column>
        </apex:pageblocktable>
        <apex:commandButton value="Save Opportunities" action="{!saveopps}"/>
    </apex:pageblock>
    <!--this block is used for displaying contact details -->
     <apex:pageblock rendered="{!flag3}">
         
     <apex:pageblocktable value="{!snts}" var="c">
        <apex:column >
            <apex:facet name="header">Contact Id</apex:facet>
            <apex:commandlink value="{!c}" Action="{!URLFOR($Action.contact.edit,c)}"/>
        </apex:column>
         <apex:column value="{!c.account.name}"/>
        <apex:column >
             <apex:facet name="header">Contact Lastname</apex:facet>
            <apex:inputtext value="{!c.lastname}"/>
        </apex:column>
        <apex:column >
        <apex:facet name="header">Contact Department</apex:facet>
            <apex:inputtext value="{!c.Department}"/>
        </apex:column>
        </apex:pageblocktable>
         <apex:commandButton value="Save Contacts" action="{!savecons}"/>
    </apex:pageblock>
   
    </apex:form>
</apex:page>
===========================================================================================

If this resolves your issue. Please mark this as solution.

Thanks :)
anu deep 6anu deep 6
Hi siva
Thanks for support.I need to fix few bugs in above code,please help me

1.)when I deselect the checkboxs of all the Account records ,empty contact and opportunity tables are dispalying.
   It should not display any empty tables if I deselect the check boxs of all the account records,there should be blank space under account table.

2.)And also If I deselect the check boxs of All the account records,opportunitites and contact check boxs should get unchecked automatically.

3.)currently we are displaying error messages in the blank space, under the account table.
      But While displaying error messages we should dispaly error messages in empty contact and opportunity tables,under the account table.
         If we deselect the account records automatically error messages should also get disappear.

please help me to fix following bugs.
Siva@51Siva@51
Hi Anudeep,

Hope this solves your all issues. If you still have any, please make sure to post them all at a time. 

Apex Class
==============================================================
public class Acc_con_Opp_Details
{
    //list of collection of the wrapper class object
    public list<accountwrapper> actwrap           {set;get;}
    //list of collection of Account,contact and opportunity objects
    public list<Account>        accounts          {set;get;}
    public list<Account>        acts              {set;get;}
    public list<opportunity>    opts              {set;get;}
    public list<opportunity>    sopts             {set;get;}
    public list<contact>        cnts              {set;get;} 
    public list<contact>        snts              {set;get;}
    public boolean oppbox                         {set;get;}//used as check box for opportunity 
    public boolean conbox                         {set;get;}//used as check box for contact
    public boolean flag1                          {set;get;}//used in account page block  
    public boolean flag2                          {set;get;}//used in contact page block 
    public boolean flag3                          {set;get;}//used in opportunity page block
    public Boolean oppError                       {set;get;}
    public Boolean conError                       {set;get;}
    //this variables are used for pagination purpose
    private integer totalRecs = 0;//stores no.of total records   
    private integer index = 0;//used for tracking offset
    private integer blockSize =5;//for setting size of page
    
   
    //in this constructor we are setting values to boolean values
    public Acc_con_Opp_Details()
    {
    flag1=true;
    flag2=false;
    flag3=false;
    oppError=false;
    conError=false;
    totalRecs = [select count() from Account];//returns total no.of account records 
    getactwrap();//calling getactwrap method.
    }
    //this method displays first five records
    public void beginning()
    {    
        flag2 = false;
        flag3 = false;
        oppbox=false;
        conbox=false;
        index = 0;
        getactwrap();
    }
    //this method displays prevoius records
     public void previous()
    {    
        flag2 = false;
        flag3 = false;
        oppbox=false;
        conbox=false;
        index = index-blockSize;
        getactwrap();
    }
    //this method displays next records
   public void next()
    {    
        flag2 = false;
        flag3 = false;
        oppbox=false;
        conbox=false;
        index = index+blockSize;
        getactwrap();
    }
    //this method displays last remaining records
 public void end()
    {    
        flag2 = false;
        flag3 = false;
        oppbox=false;
        conbox=false;
        index = totalrecs - math.mod(totalRecs,blockSize);
        getactwrap();
    }  
    //this variable is used to enable or disable first and previous buttons
 public boolean prev{get
    {
        if(index == 0)
        return true;
        else
        return false;
    }  set;}
    //this variable is used to enable or disable next and last buttons
 public boolean nxt{get
    {
        if((index + blockSize) > totalRecs)
        return true;
        else
        return false;
    }   set;}
    //used to display opportunities and contacts w.r.t selected accounts
    public void  submit()
    {
        flag1=false;
        acts=new list<Account>();
        List<Boolean> acflagList = new List<Boolean>();
        for(accountwrapper aw:actwrap)
           {
            if(aw.acflag){
                acts.add(aw.acc);
                acflagList.add(aw.acflag);
           } 
        }
        if(acflagList.isEmpty()) {
           flag2=false;
           flag3=false;
           oppError=false;
           conError=false;
        }
        
        //if we select contact check box,then it displays contacts for selected accounts 
      if(conbox)
      {
      
              snts=[select id,lastName,Department,account.name from contact where accountid IN:acts];
              if(snts.size()>0)
              {
                  flag3=true;
                  conError=false;
              }
              else
              {
                  for(accountwrapper aw : actwrap) {
                      if(aw.acflag) {
                          flag3=true;
                          conError = true;
                      }
                          //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'contact records are not found for selected Accounts.'));
                    }
              }
         } else {
             flag3 = false;
         }
        //if we select opportunity check box,then it displays opportunities for selected accounts
      if(oppbox)
        {
              opts=[select id,name,stageName,leadsource,account.name from opportunity where accountId IN:acts];
              if(opts.size() >0)
              {
                  flag2=true;
                  oppError=false;
              }
              else       
              {    
                    for(accountwrapper aw : actwrap) {
                      if(aw.acflag) {
                          flag2=true;
                          oppError = true;
                      }
                          //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'opportunity records are not found for selected Accounts.'));
                    }
              }
        } else {
            flag2 = false;
        }
    }
   //it hides contacts and dispalys opportunitites on uncheck of contact check box
   
    public void Hideandshowopp()
    {
     
        if(oppbox)
          {     
              submit();
          } else {
              flag2 = false;
          }
         
    }
   //  it hides opportunities and dispalys contacts on uncheck of opportunities check box 
     public void HideandshowCon()
    {
        if(conbox)
         {    
              submit();
          } else {
              flag3 = false;
          }
         
    }
   
    public void Hideandshowoppcon() {
        Hideandshowopp();
        Hideandshowcon();
    }
    
    
    //This method uses a simple SOQL query to return a List of Accounts
     public void getactwrap() {
         accounts = Database.Query('SELECT id,Name,phone FROM Account LIMIT :blockSize OFFSET :index');
         actwrap=new list<accountwrapper>();
       // As each Account is processed we create a new accountwrapper object and add it to the wrapper class(accountwrapper) list.
         for(account a:accounts)
        {
            actwrap.add(new accountwrapper(a));
        }
    }
    // this method  uses dml operation to edit the existing opportunities values or to insert new oppt values
    public void saveopps()
    {
        list<opportunity> opps=new list<opportunity>();
        opps.addAll(opts);
        upsert opps;
    }
    //his method  uses dml operation to edit the existing contact values or to insert new contact values
    public void savecons()
    {
       cnts = new list<contact>();
        cnts.addall(snts);
        upsert cnts;
    }
 //This is wrapper class which is collection of other class instances
  //here  wrapper class contains both the standard salesforce object Account and a Boolean value acflag   
 public class accountwrapper{
        public account acc{set;get;}
        public boolean acflag{set;get;}
             //In this contructor When we create a new accountwrapper object we pass a Account that is set to the acc property.
             // We also set the boolean value to false
        public accountwrapper(account a){
            acc=a;
            acflag=false;
        }
        
    }

}
==================================================
Page
===================================================
<apex:page controller="Acc_con_Opp_Details" showHeader="false" docType="html-5.0">
<apex:form >

    <!--This block dispalying account record details-->
    <apex:pageblock rendered="true">
    <apex:pageMessages ></apex:pageMessages>
    <apex:pageblocktable value="{!actwrap}" var="a">
        <apex:column >
    <apex:facet name="header" >Select</apex:facet>
             <apex:inputCheckbox value="{!a.acflag}">
                 <apex:actionSupport event="onchange" action="{!Hideandshowoppcon}"/>
             </apex:inputCheckbox>
        </apex:column>
        <!-- displays id,name and phone number for accounts-->
        <apex:column value="{!a.acc.id}"/>
        <apex:column value="{!a.acc.name}"/>
        <apex:column value="{!a.acc.phone}"/>
         </apex:pageblocktable>
        <!-- this buttons are used to paginate account records-->
        <apex:pageblockButtons >
            <!--displays first five records-->
            <apex:commandButton value="first"  action="{!beginning}" disabled="{!prev}"/>
            <!--displays previous records-->
            <apex:commandButton value="previous"  action="{!previous}" disabled="{!prev}"/>
             <!--displays previous  next records-->
            <apex:commandButton value="next"  action="{!next}" disabled="{!nxt}"/>
            <!-- displays last records-->
            <apex:commandButton value="last"  action="{!end}" disabled="{!nxt}"/>                                    
        </apex:pageblockButtons>
         <!-- check boxs for opportunities and contacts-->
        
     <center>  <apex:inputCheckbox value="{!oppbox}">
     <apex:actionSupport event="onchange" action="{!Hideandshowopp}"/>
     </apex:inputCheckbox>Opportunities&nbsp;&nbsp;&nbsp;
         <apex:inputCheckbox value="{!conbox}">
         <apex:actionSupport event="onchange" action="{!HideandshowCon}"/>
         </apex:inputCheckbox>Contacts&nbsp;&nbsp;&nbsp;
        <apex:commandButton value="submit" action="{!submit}"/>
       </center>
    </apex:pageblock>
    <!--this block displays opportunity details-->
    <apex:pageblock rendered="{!flag2}" id="block" >
       
   <apex:pageblocktable value="{!opts}" var="o">
        <apex:column >
             <apex:facet name="header">Opportunity Id</apex:facet>
            <apex:commandlink value="{!o.id}" Action="{!URLFOR($Action.opportunity.edit,o.Id)}"/>
        </apex:column>
        <apex:column value="{!o.account.name}" />
        <apex:column >
            <apex:facet name="header">Opportunity Name</apex:facet>
       <apex:inputtext value="{!o.name}" />
            </apex:column>
        <apex:column >
           <apex:facet name="header">Opportunity Stage</apex:facet> 
       <apex:inputtext value="{!o.stagename}"/>
        </apex:column>
       <apex:column >
         <apex:facet name="header">Opportunity Leadsource</apex:facet> 
        </apex:column>
        </apex:pageblocktable>
        <apex:pageMessage rendered="{!oppError}" severity="error" strength="1" summary="No Opportunites Found" />
        <apex:commandButton value="Save Opportunities" action="{!saveopps}"/>
    </apex:pageblock>
    <!--this block is used for displaying contact details -->
     <apex:pageblock rendered="{!flag3}">
         
     <apex:pageblocktable value="{!snts}" var="c">
        <apex:column >
            <apex:facet name="header">Contact Id</apex:facet>
            <apex:commandlink value="{!c}" Action="{!URLFOR($Action.contact.edit,c)}"/>
        </apex:column>
         <apex:column value="{!c.account.name}"/>
        <apex:column >
             <apex:facet name="header">Contact Lastname</apex:facet>
            <apex:inputtext value="{!c.lastname}"/>
        </apex:column>
        <apex:column >
        <apex:facet name="header">Contact Department</apex:facet>
            <apex:inputtext value="{!c.Department}"/>
        </apex:column>
        </apex:pageblocktable>
        <apex:pageMessage rendered="{!conError}" severity="error" strength="1" summary="No Contacts Found" /> 
         <apex:commandButton value="Save Contacts" action="{!savecons}"/>
    </apex:pageblock>
   
    </apex:form>
</apex:page>
================================================================

If this resolves your issue. Please mark this as solution.

Thanks :)
anu deep 6anu deep 6
HI siva 

Sorry for troubling you,and interupting you again and again.Greatly appreciating your help.Few more functionalities need to be achieved in above code,I here by requesting you to help me


1. while unchecking the last account record, both Opportunities,contact checkboxes should be deselected, because there are no accounts selected.

means:if we uncheck all the accout records,Opportunities and contact check boxs need to be  unchecked automatically.
=====
5. Sorting of account records based on name field upon clicking on column header. Default order is ascending and upon clicking the header it should change to descending and vice versa.

6. Need a provision to the user to select all records at a time on click of a check box which display at the account header level. 
     means:- there should be a header check box ,if we select that check box all account records check boxes need to be checked automatically,if             we deselect that header check box all the account check boxs need to be  unchecked automaticcaly.

               
 
Siva@51Siva@51
Hi anudeep,

Apex Class
======================================================
public class Acc_con_Opp_Details
{
    //list of collection of the wrapper class object
    public list<accountwrapper> actwrap           {set;get;}
    //list of collection of Account,contact and opportunity objects
    public list<Account>        accounts          {set;get;}
    public list<Account>        acts              {set;get;}
    public list<opportunity>    opts              {set;get;}
    public list<opportunity>    sopts             {set;get;}
    public list<contact>        cnts              {set;get;} 
    public list<contact>        snts              {set;get;}
    public boolean oppbox                         {set;get;}//used as check box for opportunity 
    public boolean conbox                         {set;get;}//used as check box for contact
    public boolean flag1                          {set;get;}//used in account page block  
    public boolean flag2                          {set;get;}//used in contact page block 
    public boolean flag3                          {set;get;}//used in opportunity page block
    public boolean checkallflag                   {set;get;}
    public Boolean oppError                       {set;get;}
    public Boolean conError                       {set;get;}
    //this variables are used for pagination purpose
    private integer totalRecs = 0;//stores no.of total records   
    private integer index = 0;//used for tracking offset
    private integer blockSize =5;//for setting size of page
    private String sortDirection = 'ASC';
    private String sortExp = 'Name';
    
    //in this constructor we are setting values to boolean values
    public Acc_con_Opp_Details()
    {
    flag1=true;
    flag2=false;
    flag3=false;
    oppError=false;
    conError=false;
    checkallflag = false;
    totalRecs = [select count() from Account];//returns total no.of account records 
    getactwrap();//calling getactwrap method.
    }
    public String sortExpression
    {
      get
      {
         return sortExp;
      }
      set
      {
        //if the column is clicked on then switch between Ascending and Descending modes
        if (value == sortExp)
          sortDirection = (sortDirection == 'ASC')? 'DESC' : 'ASC';
        else
          sortDirection = 'ASC';
          sortExp = value;
      }
    }

    public String getSortDirection()
    {
       //if not column is selected 
       if (sortExpression == null || sortExpression == '')
           return 'ASC';
       else
          return sortDirection;
    }

    public void setSortDirection(String value)
    {  
        sortDirection = value;
    }
    //this method displays first five records
    public void beginning()
    {    
        flag2 = false;
        flag3 = false;
        oppbox=false;
        conbox=false;
        checkallflag=false;
        index = 0;
        getactwrap();
    }
    //this method displays prevoius records
     public void previous()
    {    
        flag2 = false;
        flag3 = false;
        oppbox=false;
        conbox=false;
        checkallflag=false;
        index = index-blockSize;
        getactwrap();
    }
    //this method displays next records
   public void next()
    {    
        flag2 = false;
        flag3 = false;
        oppbox=false;
        conbox=false;
        checkallflag=false;
        index = index+blockSize;
        getactwrap();
    }
    //this method displays last remaining records
 public void end()
    {    
        flag2 = false;
        flag3 = false;
        oppbox=false;
        conbox=false;
        checkallflag=false;
        index = totalrecs - math.mod(totalRecs,blockSize);
        getactwrap();
    }  
    //this variable is used to enable or disable first and previous buttons
 public boolean prev{get
    {
        if(index == 0)
        return true;
        else
        return false;
    }  set;}
    //this variable is used to enable or disable next and last buttons
 public boolean nxt{get
    {
        if((index + blockSize) > totalRecs)
        return true;
        else
        return false;
    }   set;}
    //used to display opportunities and contacts w.r.t selected accounts
    public void  submit()
    {
        flag1=false;
        acts=new list<Account>();
        List<Boolean> acflagList = new List<Boolean>();
        for(accountwrapper aw:actwrap)
           {
            if(aw.acflag){
                acts.add(aw.acc);
                acflagList.add(aw.acflag);
           } 
        }
        if(acflagList.isEmpty()) {
           oppbox=false;
           conbox=false;
           flag2=false;
           flag3=false;
           oppError=false;
           conError=false;
        }
        
        //if we select contact check box,then it displays contacts for selected accounts 
      if(conbox)
      {
      
              snts=[select id,lastName,Department,account.name from contact where accountid IN:acts];
              if(snts.size()>0)
              {
                  flag3=true;
                  conError=false;
              }
              else
              {
                  for(accountwrapper aw : actwrap) {
                      if(aw.acflag) {
                          flag3=true;
                          conError = true;
                      }
                          //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'contact records are not found for selected Accounts.'));
                    }
              }
         } else {
             flag3 = false;
         }
        //if we select opportunity check box,then it displays opportunities for selected accounts
      if(oppbox)
        {
              opts=[select id,name,stageName,leadsource,account.name from opportunity where accountId IN:acts];
              if(opts.size() >0)
              {
                  flag2=true;
                  oppError=false;
              }
              else       
              {    
                    for(accountwrapper aw : actwrap) {
                      if(aw.acflag) {
                          flag2=true;
                          oppError = true;
                      }
                          //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'opportunity records are not found for selected Accounts.'));
                    }
              }
        } else {
            flag2 = false;
        }
    }
   //it hides contacts and dispalys opportunitites on uncheck of contact check box
   
    public void Hideandshowopp()
    {
     
        if(oppbox)
          {     
              submit();
          } else {
              flag2 = false;
          }
         
    }
   //  it hides opportunities and dispalys contacts on uncheck of opportunities check box 
     public void HideandshowCon()
    {
        if(conbox)
         {    
              submit();
          } else {
              flag3 = false;
          }
         
    }
   
    public void Hideandshowoppcon() {
        Hideandshowopp();
        Hideandshowcon();
    }
    
    //This method uses a simple SOQL query to return a List of Accounts
     public void getactwrap() {
         string sortFullExp = sortExpression  + ' ' + sortDirection;
         accounts = Database.Query('SELECT id,Name,phone FROM Account order by ' + sortFullExp + ' LIMIT :blockSize OFFSET :index');
         actwrap=new list<accountwrapper>();
       // As each Account is processed we create a new accountwrapper object and add it to the wrapper class(accountwrapper) list.
         for(account a:accounts)
        {
            actwrap.add(new accountwrapper(a));
        }
    }
    
    // this method  uses dml operation to edit the existing opportunities values or to insert new oppt values
    public void saveopps()
    {
        list<opportunity> opps=new list<opportunity>();
        opps.addAll(opts);
        upsert opps;
    }
    //his method  uses dml operation to edit the existing contact values or to insert new contact values
    public void savecons()
    {
       cnts = new list<contact>();
        cnts.addall(snts);
        upsert cnts;
    }
 //This is wrapper class which is collection of other class instances
  //here  wrapper class contains both the standard salesforce object Account and a Boolean value acflag   
 public class accountwrapper{
        public account acc{set;get;}
        public boolean acflag{set;get;}
             //In this contructor When we create a new accountwrapper object we pass a Account that is set to the acc property.
             // We also set the boolean value to false
        public accountwrapper(account a){
            acc=a;
            acflag=false;
        }
        
    }

}

=========================================================
Page
=========================================================
<apex:page controller="Acc_con_Opp_Details" showHeader="false" docType="html-5.0">
    <script>
    function checkallflag(allCheckboxes) {
    
        var container = allCheckboxes;
        while (container.tagName != "TABLE") {
            container = container.parentNode;
        }
    
        var inputs = container.getElementsByTagName("input");
        var checked = allCheckboxes.checked;
        for (var i = 0; i < inputs.length; i++) { 
            var input = inputs.item(i);
            if (input.type == "checkbox") {
                if (input != allCheckboxes) {
                    input.checked = checked;
                }
            }
        }
        CallSubmitMethod();
    }
    </script>
    <apex:form >
    <apex:actionFunction name="CallSubmitMethod" action="{!submit}"/>
    <!--This block dispalying account record details-->
    <apex:pageblock rendered="true">
    <apex:pageMessages ></apex:pageMessages>
    <apex:pageblocktable value="{!actwrap}" var="a">
        <apex:column>
            <apex:facet name="header">
                <apex:inputCheckbox onclick="checkallflag(this)" value="{!checkallflag}"/>
            </apex:facet>
            <!--<apex:facet name="header">Select</apex:facet>-->
             <apex:inputCheckbox value="{!a.acflag}">
                 <apex:actionSupport event="onchange" action="{!Hideandshowoppcon}"/>
             </apex:inputCheckbox>
        </apex:column>
        <!-- displays id,name and phone number for accounts-->
        <apex:column value="{!a.acc.id}"/>
        <apex:column>
         <apex:facet name="header">   
           <apex:commandLink action="{!getactwrap}" value="Name{!IF(sortExpression=='name',IF(sortDirection='ASC','▼','▲'),'▼')}">
             <apex:param value="name" name="column" assignTo="{!sortExpression}" ></apex:param>
           </apex:commandLink>
         </apex:facet>
         <apex:outputLabel>{!a.acc.Name}</apex:outputLabel>
       </apex:column>
        <apex:column value="{!a.acc.phone}"/>
         </apex:pageblocktable>
        <!-- this buttons are used to paginate account records-->
        <apex:pageblockButtons >
            <!--displays first five records-->
            <apex:commandButton value="first"  action="{!beginning}" disabled="{!prev}"/>
            <!--displays previous records-->
            <apex:commandButton value="previous"  action="{!previous}" disabled="{!prev}"/>
             <!--displays previous  next records-->
            <apex:commandButton value="next"  action="{!next}" disabled="{!nxt}"/>
            <!-- displays last records-->
            <apex:commandButton value="last"  action="{!end}" disabled="{!nxt}"/>                                    
        </apex:pageblockButtons>
         <!-- check boxs for opportunities and contacts-->
        
     <center>  <apex:inputCheckbox value="{!oppbox}">
     <apex:actionSupport event="onchange" action="{!Hideandshowopp}"/>
     </apex:inputCheckbox>Opportunities&nbsp;&nbsp;&nbsp;
         <apex:inputCheckbox value="{!conbox}">
         <apex:actionSupport event="onchange" action="{!HideandshowCon}"/>
         </apex:inputCheckbox>Contacts&nbsp;&nbsp;&nbsp;
        <apex:commandButton value="submit" action="{!submit}"/>
       </center>
    </apex:pageblock>
    <!--this block displays opportunity details-->
    <apex:pageblock rendered="{!flag2}" id="block" >
       
   <apex:pageblocktable value="{!opts}" var="o">
        <apex:column >
             <apex:facet name="header">Opportunity Id</apex:facet>
            <apex:commandlink value="{!o.id}" Action="{!URLFOR($Action.opportunity.edit,o.Id)}"/>
        </apex:column>
        <apex:column value="{!o.account.name}" />
        <apex:column >
            <apex:facet name="header">Opportunity Name</apex:facet>
       <apex:inputtext value="{!o.name}" />
            </apex:column>
        <apex:column >
           <apex:facet name="header">Opportunity Stage</apex:facet> 
       <apex:inputtext value="{!o.stagename}"/>
        </apex:column>
       <apex:column >
         <apex:facet name="header">Opportunity Leadsource</apex:facet> 
        </apex:column>
        </apex:pageblocktable>
        <apex:pageMessage rendered="{!oppError}" severity="error" strength="1" summary="No Opportunites Found" />
        <apex:commandButton value="Save Opportunities" action="{!saveopps}"/>
    </apex:pageblock>
    <!--this block is used for displaying contact details -->
     <apex:pageblock rendered="{!flag3}">
         
     <apex:pageblocktable value="{!snts}" var="c">
        <apex:column >
            <apex:facet name="header">Contact Id</apex:facet>
            <apex:commandlink value="{!c}" Action="{!URLFOR($Action.contact.edit,c)}"/>
        </apex:column>
         <apex:column value="{!c.account.name}"/>
        <apex:column >
             <apex:facet name="header">Contact Lastname</apex:facet>
            <apex:inputtext value="{!c.lastname}"/>
        </apex:column>
        <apex:column >
        <apex:facet name="header">Contact Department</apex:facet>
            <apex:inputtext value="{!c.Department}"/>
        </apex:column>
        </apex:pageblocktable>
        <apex:pageMessage rendered="{!conError}" severity="error" strength="1" summary="No Contacts Found" /> 
         <apex:commandButton value="Save Contacts" action="{!savecons}"/>
    </apex:pageblock>
   
    </apex:form>
</apex:page>

=======================================================================

 
anu deep 6anu deep 6
Hi Siva

I here by requesting you to please fix below bugs in above code

1.)while selecting and deselecting account records check box,screen is getting blinking.

2.) If we uncheck account recocrds header check box automatically opportunities and contacts check boxs are unchecking that's fine.But if we select account records individually with out selecting header check box and deselect  them individually,Opportunities and contacts check boxs are not getting unchecked.

note:-even though if we select few account records individually with out selecting master check box,on deselection of that account records,automatically opportunities and contacts check boxs should get unchecked.
  
please help me out by resolving above bugs.
 
anu deep 6anu deep 6
Hi siva,

I am waiting for your reply,please help me.
anu deep 6anu deep 6
Hi siva,

Sorry for troubling you,Please ingore above issues.I soved them

1.)First issue blinking scrren was solved by using <apex:outputpanel> component.

2.)second one is not a bug,It was working properly sorry of puting you in confusion.

If any more is required I will let you know,Thanks for support.
anu deep 6anu deep 6
HI siva,

I here by requesting you to please help me to achieve following enchancements in above code

1.)Display all alphabets with command links on the account's table and upon click on any of the letter,account table should display account's records starting with the selected letter.

2.)If no account's records is selected and user clicks on opportunities/contacts check boxs then it should show error message that 'Choose atleast one account record to display opportunities' error message.Same is the case with contacts also.
User-added image

3.)If no opportunities/contacts records are found for the selected account records, it should not display save opportunities/contacts button.
     In above screen shot,you can observe that no opportunities are are found for selected accounts and it was displaying save opportunities button under opportunities table.we need to avoid that  save opportunities button,if no opportunities are found for selected accounts.

please help me to achieve above mentioned functionalities in above code.
anu deep 6anu deep 6
HI siva,

I am waiting for your reply,Please help me to achieve above enchancements.
anu deep 6anu deep 6
Hi siva,

I am waiting for your reply,Please help me by achieving above mentioned functionalities.Greatly apprerciate your help.
Siva@51Siva@51
Hi Anudeep,

Sorry, Busy with my work. Please share your modified code. Will look into that today.
anu deep 6anu deep 6
Hi siva,

No issues,Thanks for your kind reply.

1.)Display all alphabets with command links on the account's table and upon click on any of the letter,account table should display account's records starting with the selected letter.

2.)If no account's records is selected and user clicks on opportunities/contacts check boxs then it should show error message that 'Choose atleast one account record to display opportunities' error message.Same is the case with contacts also.
User-added image

3.)If no opportunities/contacts records are found for the selected account records, it should not display save opportunities/contacts button.
     In above screen shot,you can observe that no opportunities are are found for selected accounts and it was displaying save opportunities button under opportunities table.we need to avoid that  save opportunities button,if no opportunities are found for selected accounts.

please try to achieve above functionalities in below code.

Apex controller
===========

public class Acc_con_Opp_Details
{
    //list of collection of the wrapper class object
    public list<accountwrapper> actwrap           {set;get;}
    //list of collection of Account,contact and opportunity objects
    public list<Account>        accounts          {set;get;}
    public list<Account>        acts              {set;get;}
    public list<opportunity>    opts              {set;get;}
    public list<opportunity>    sopts             {set;get;}
    public list<contact>        cnts              {set;get;} 
    public list<contact>        snts              {set;get;}
    public boolean oppbox                         {set;get;}//used as check box for opportunity 
    public boolean conbox                         {set;get;}//used as check box for contact
    public boolean flag1                          {set;get;}//used in account page block  
    public boolean flag2                          {set;get;}//used in contact page block 
    public boolean flag3                          {set;get;}//used in opportunity page block
    public boolean checkallflag                   {set;get;}//used for header check box
    public Boolean oppError                       {set;get;}
    public Boolean conError                       {set;get;}
    //this variables are used for pagination purpose
    private integer totalRecs = 0;//stores no.of total records   
    private integer index = 0;//used for tracking offset
    private integer blockSize =5;//for setting size of page
    private String sortDirection = 'ASC';
    private String sortExp = 'Name';
    
    //in this constructor we are setting values to boolean values
    public Acc_con_Opp_Details()
    {
    flag1=true;
    flag2=false;
    flag3=false;
    oppError=false;
    conError=false;
    checkallflag = false;
    totalRecs = [select count() from Account];//returns total no.of account records 
    getactwrap();//calling getactwrap method.
    }
    public String sortExpression
    {
      get
      {
         return sortExp;
      }
      set
      {
        //if the column is clicked on then switch between Ascending and Descending modes
        if (value == sortExp)
          sortDirection = (sortDirection == 'ASC')? 'DESC' : 'ASC';
        else
          sortDirection = 'ASC';
          sortExp = value;
      }
    }

    public String getSortDirection()
    {
       //if not column is selected 
       if (sortExpression == null || sortExpression == '')
           return 'ASC';
       else
          return sortDirection;
    }

    public void setSortDirection(String value)
    {  
        sortDirection = value;
    }
    //this method displays first five records
    public void beginning()
    {    
        flag2 = false;
        flag3 = false;
        oppbox=false;
        conbox=false;
        checkallflag=false;
        index = 0;
        getactwrap();
    }
    //this method displays prevoius records
     public void previous()
    {    
        flag2 = false;
        flag3 = false;
        oppbox=false;
        conbox=false;
        checkallflag=false;
        index = index-blockSize;
        getactwrap();
    }
    //this method displays next records
   public void next()
    {    
        flag2 = false;
        flag3 = false;
        oppbox=false;
        conbox=false;
        checkallflag=false;
        index = index+blockSize;
        getactwrap();
    }
    //this method displays last remaining records
 public void end()
    {    
        flag2 = false;
        flag3 = false;
        oppbox=false;
        conbox=false;
        checkallflag=false;
        index = totalrecs - math.mod(totalRecs,blockSize);
        getactwrap();
    }  
    //this variable is used to enable or disable first and previous buttons
 public boolean prev{get
    {
        if(index == 0)
        return true;
        else
        return false;
    }  set;}
    //this variable is used to enable or disable next and last buttons
 public boolean nxt{get
    {
        if((index + blockSize) > totalRecs)
        return true;
        else
        return false;
    }   set;}
    //used to display opportunities and contacts w.r.t selected accounts
    public void  submit()
    {
        flag1=false;
        acts=new list<Account>();
        List<Boolean> acflagList = new List<Boolean>();
        for(accountwrapper aw:actwrap)
           {
            if(aw.acflag){
                acts.add(aw.acc);
                acflagList.add(aw.acflag);
           } 
        }
        if(acflagList.isEmpty()) {
           oppbox=false;
           conbox=false;
           flag2=false;
           flag3=false;
           oppError=false;
           conError=false;
        }
        
        //if we select contact check box,then it displays contacts for selected accounts 
      if(conbox)
      {
      
              snts=[select id,lastName,Department,account.name from contact where accountid IN:acts];
              if(snts.size()>0)
              {
                  flag3=true;
                  conError=false;
              }
              else
              {
                  for(accountwrapper aw : actwrap) {
                      if(aw.acflag) {
                          flag3=true;
                          conError = true;
                      }
                          //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'contact records are not found for selected Accounts.'));
                    }
              }
         } else {
             flag3 = false;
         }
        //if we select opportunity check box,then it displays opportunities for selected accounts
      if(oppbox)
        {
              opts=[select id,name,stageName,leadsource,account.name from opportunity where accountId IN:acts];
              if(opts.size() >0)
              {
                  flag2=true;
                  oppError=false;
              }
              else       
              {    
                    for(accountwrapper aw : actwrap) {
                      if(aw.acflag) {
                          flag2=true;
                          oppError = true;
                      }
                          //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'opportunity records are not found for selected Accounts.'));
                    }
              }
        } else {
            flag2 = false;
        }
    }
   //it hides contacts and dispalys opportunitites on uncheck of contact check box
   
    public void Hideandshowopp()
    {
     
        if(oppbox)
          {     
              submit();
          } else {
              flag2 = false;
          }
         
    }
   //  it hides opportunities and dispalys contacts on uncheck of opportunities check box 
     public void HideandshowCon()
    {
        if(conbox)
         {    
              submit();
          } else {
              flag3 = false;
          }
         
    }
   
    public void Hideandshowoppcon() {
        Hideandshowopp();
        Hideandshowcon();
    }
    
    //This method uses a simple SOQL query to return a List of Accounts
     public void getactwrap() {
         string sortFullExp = sortExpression  + ' ' + sortDirection;
         accounts = Database.Query('SELECT id,Name,phone FROM Account order by ' + sortFullExp + ' LIMIT :blockSize OFFSET :index');
         actwrap=new list<accountwrapper>();
       // As each Account is processed we create a new accountwrapper object and add it to the wrapper class(accountwrapper) list.
         for(account a:accounts)
        {
            actwrap.add(new accountwrapper(a));
        }
    }
    
    // this method  uses dml operation to edit the existing opportunities values or to insert new oppt values
    public void saveopps()
    {
        list<opportunity> opps=new list<opportunity>();
        opps.addAll(opts);
        upsert opps;
    }
    //his method  uses dml operation to edit the existing contact values or to insert new contact values
    public void savecons()
    {
       cnts = new list<contact>();
        cnts.addall(snts);
        upsert cnts;
    }
 //This is wrapper class which is collection of other class instances
  //here  wrapper class contains both the standard salesforce object Account and a Boolean value acflag   
 public class accountwrapper{
        public account acc{set;get;}
        public boolean acflag{set;get;}
             //In this contructor When we create a new accountwrapper object we pass a Account that is set to the acc property.
             // We also set the boolean value to false
        public accountwrapper(account a){
            acc=a;
            acflag=false;
        }
        
    }

}

vf page
======
<apex:page controller="Acc_con_Opp_Details" showHeader="false" docType="html-5.0">
    <script>
    function checkallflag(allCheckboxes) {
    
        var container = allCheckboxes;
        while (container.tagName != "TABLE") {
            container = container.parentNode;
        }
    
        var inputs = container.getElementsByTagName("input");
        var checked = allCheckboxes.checked;
        for (var i = 0; i < inputs.length; i++) { 
            var input = inputs.item(i);
            if (input.type == "checkbox") {
                if (input != allCheckboxes) {
                    input.checked = checked;
                }
            }
        }
        CallSubmitMethod();
    }
    </script>
    <apex:form >
    <apex:actionFunction name="CallSubmitMethod" action="{!submit}"/>
    <!--This block dispalying account record details-->
        <apex:outputPanel id="par">
        
           
    <apex:pageblock rendered="true">
        <apex:commandLink value="a"/>&nbsp;<apex:commandLink value="b"/>&nbsp;<apex:commandLink value="c"/>&nbsp;<apex:commandLink value="d"/>&nbsp;<apex:commandLink value="e"/>&nbsp;<apex:commandLink value="f"/>&nbsp;<apex:commandLink value="g"/>&nbsp;<apex:commandLink value="h"/>&nbsp;<apex:commandLink value="i"/>
        &nbsp;<apex:commandLink value="j"/>&nbsp;<apex:commandLink value="k"/>&nbsp;<apex:commandLink value="l"/>&nbsp;<apex:commandLink value="m"/>&nbsp;<apex:commandLink value="n"/>&nbsp;<apex:commandLink value="o"/>&nbsp;<apex:commandLink value="p"/>&nbsp;<apex:commandLink value="q"/>&nbsp;<apex:commandLink value="r"/>
        &nbsp;<apex:commandLink value="s"/>&nbsp;<apex:commandLink value="t"/>&nbsp;<apex:commandLink value="u"/>&nbsp;<apex:commandLink value="v"/>&nbsp;<apex:commandLink value="w"/>&nbsp;<apex:commandLink value="x"/>&nbsp;<apex:commandLink value="y"/>&nbsp;<apex:commandLink value="z"/>
            
    <apex:pageMessages ></apex:pageMessages>
    <apex:pageblocktable value="{!actwrap}" var="a">
        <apex:column >
            <apex:facet name="header">
                <apex:inputCheckbox onclick="checkallflag(this)" value="{!checkallflag}"/>
            </apex:facet>
            <!--<apex:facet name="header">Select</apex:facet>-->
             <apex:inputCheckbox value="{!a.acflag}">
                 <apex:actionSupport event="onchange" action="{!Hideandshowoppcon}" reRender="par"/>
             </apex:inputCheckbox>
        </apex:column>
        <!-- displays id,name and phone number for accounts-->
        <apex:column value="{!a.acc.id}"/>
        <apex:column >
         <apex:facet name="header">   
           
           <apex:commandLink action="{!getactwrap}" value="Name{!IF(sortExpression=='name',IF(sortDirection='ASC','▼','▲'),'▼')}">
             <apex:param value="name" name="column" assignTo="{!sortExpression}"></apex:param>
           </apex:commandLink>
         </apex:facet>
         <apex:outputLabel >{!a.acc.Name}</apex:outputLabel>
       </apex:column>
        <apex:column value="{!a.acc.phone}"/>
         </apex:pageblocktable>
        <!-- this buttons are used to paginate account records-->
      
        <apex:pageblockButtons location="top">
            <!--displays first five records-->
            <apex:commandButton value="first"  action="{!beginning}" disabled="{!prev}"/>
            <!--displays previous records-->
            <apex:commandButton value="previous"  action="{!previous}" disabled="{!prev}"/>
             <!--displays previous  next records-->
            <apex:commandButton value="next"  action="{!next}" disabled="{!nxt}"/>
            <!-- displays last records-->
            <apex:commandButton value="last"  action="{!end}" disabled="{!nxt}"/>                                    
        </apex:pageblockButtons>
         <!-- check boxs for opportunities and contacts-->
       
     <center>  <apex:inputCheckbox value="{!oppbox}">
     <apex:actionSupport event="onchange" action="{!Hideandshowopp}"/>
     </apex:inputCheckbox>Opportunities&nbsp;&nbsp;&nbsp;
         <apex:inputCheckbox value="{!conbox}">
         <apex:actionSupport event="onchange" action="{!HideandshowCon}"/>
         </apex:inputCheckbox>Contacts&nbsp;&nbsp;&nbsp;
       <!-- <apex:commandButton value="submit" action="{!submit}"/>-->
       </center>
    </apex:pageblock>
    <!--this block displays opportunity details-->
    
    <apex:pageblock rendered="{!flag2}">
       
   <apex:pageblocktable value="{!opts}" var="o">
        <apex:column >
             <apex:facet name="header">Opportunity Id</apex:facet>
            <apex:commandlink value="{!o.id}" Action="{!URLFOR($Action.opportunity.edit,o.Id)}"/>
        </apex:column>
        <apex:column value="{!o.account.name}" />
        <apex:column >
            <apex:facet name="header">Opportunity Name</apex:facet>
       <apex:inputtext value="{!o.name}" />
            </apex:column>
        <apex:column >
           <apex:facet name="header">Opportunity Stage</apex:facet> 
       <apex:inputtext value="{!o.stagename}"/>
        </apex:column>
       <apex:column >
         <apex:facet name="header">Opportunity Leadsource</apex:facet> 
        </apex:column>
        </apex:pageblocktable>
        <apex:pageMessage rendered="{!oppError}" severity="error" strength="1" summary="No Opportunites Found" />
        <apex:commandButton value="Save Opportunities" action="{!saveopps}"/>
    </apex:pageblock>
             
    <!--this block is used for displaying contact details -->
            
     <apex:pageblock rendered="{!flag3}">
         
     <apex:pageblocktable value="{!snts}" var="c">
        <apex:column >
            <apex:facet name="header">Contact Id</apex:facet>
            <apex:commandlink value="{!c}" Action="{!URLFOR($Action.contact.edit,c)}"/>
        </apex:column>
         <apex:column value="{!c.account.name}" />
        <apex:column >
             <apex:facet name="header">Contact Lastname</apex:facet>
            <apex:inputtext value="{!c.lastname}"/>
        </apex:column>
        <apex:column >
        <apex:facet name="header">Contact Department</apex:facet>
            <apex:inputtext value="{!c.Department}"/>
        </apex:column>
        </apex:pageblocktable>
        <apex:pageMessage rendered="{!conError}" severity="error" strength="1" summary="No Contacts Found" /> 
         <apex:commandButton value="Save Contacts" action="{!savecons}" />
    </apex:pageblock>
       
        </apex:outputPanel>
    </apex:form>
</apex:page>
Siva@51Siva@51
Hi Anudeep,
Here you go
Apex Class
===================================================================
public class Acc_con_Opp_Details
{
    //list of collection of the wrapper class object
    public list<accountwrapper> actwrap           {set;get;}
    //list of collection of Account,contact and opportunity objects
    public list<Account>        accounts          {set;get;}
    public list<Account>        acts              {set;get;}
    public list<opportunity>    opts              {set;get;}
    public list<opportunity>    sopts             {set;get;}
    public list<contact>        cnts              {set;get;} 
    public list<contact>        snts              {set;get;}
    public boolean oppbox                         {set;get;}//used as check box for opportunity 
    public boolean conbox                         {set;get;}//used as check box for contact
    public boolean flag1                          {set;get;}//used in account page block  
    public boolean flag2                          {set;get;}//used in contact page block 
    public boolean flag3                          {set;get;}//used in opportunity page block
    public boolean checkallflag                   {set;get;}//used for header check box
    public Boolean oppError                       {set;get;}
    public Boolean conError                       {set;get;}
    public list<String> AlphaList                 {get; set;}
    public String AlphaFilter                     {get; set;}
    private String Query;
    //this variables are used for pagination purpose
    private integer totalRecs = 0;//stores no.of total records   
    private integer index = 0;//used for tracking offset
    private integer blockSize =5;//for setting size of page
    private String sortDirection = 'ASC';
    private String sortExp = 'Name';
    public Map<String, String> mapAlpha{get; set;}
 
    //in this constructor we are setting values to boolean values
    public Acc_con_Opp_Details()
    {
    flag1=true;
    flag2=false;
    flag3=false;
    oppError=false;
    conError=false;
    checkallflag = false;
    totalRecs = [select count() from Account];//returns total no.of account records 
    getactwrap();//calling getactwrap method.
    AlphaList = new list<String> {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'Other', 'All'};
    if (apexpages.currentpage().getparameters().get('alpha') == null) {
        AlphaFilter = 'All';
    } else {
        AlphaFilter = apexpages.currentpage().getparameters().get('alpha');
    }
    }
    public String sortExpression
    {
      get
      {
         return sortExp;
      }
      set
      {
        //if the column is clicked on then switch between Ascending and Descending modes
        if (value == sortExp)
          sortDirection = (sortDirection == 'ASC')? 'DESC' : 'ASC';
        else
          sortDirection = 'ASC';
          sortExp = value;
      }
    }

    public String getSortDirection()
    {
       //if not column is selected 
       if (sortExpression == null || sortExpression == '')
           return 'ASC';
       else
          return sortDirection;
    }

    public void setSortDirection(String value)
    {  
        sortDirection = value;
    }
    //this method displays first five records
    public void beginning()
    {    
        flag2 = false;
        flag3 = false;
        oppbox=false;
        conbox=false;
        checkallflag=false;
        index = 0;
        getactwrap();
    }
    //this method displays prevoius records
     public void previous()
    {    
        flag2 = false;
        flag3 = false;
        oppbox=false;
        conbox=false;
        checkallflag=false;
        index = index-blockSize;
        getactwrap();
    }
    //this method displays next records
   public void next()
    {    
        flag2 = false;
        flag3 = false;
        oppbox=false;
        conbox=false;
        checkallflag=false;
        index = index+blockSize;
        getactwrap();
    }
    //this method displays last remaining records
 public void end()
    {    
        flag2 = false;
        flag3 = false;
        oppbox=false;
        conbox=false;
        checkallflag=false;
        index = totalrecs - math.mod(totalRecs,blockSize);
        getactwrap();
    }  
    //this variable is used to enable or disable first and previous buttons
 public boolean prev{get
    {
        if(index == 0)
        return true;
        else
        return false;
    }  set;}
    //this variable is used to enable or disable next and last buttons
 public boolean nxt{get
    {
        if((index + blockSize) > totalRecs)
        return true;
        else
        return false;
    }   set;}
    //used to display opportunities and contacts w.r.t selected accounts
    public void  submit()
    {
        flag1=false;
        acts=new list<Account>();
        List<Boolean> acflagList = new List<Boolean>();
        for(accountwrapper aw:actwrap)
           {
            if(aw.acflag){
                acts.add(aw.acc);
                acflagList.add(aw.acflag);
           } 
        }
        if(acflagList.isEmpty()) {
           oppbox=false;
           conbox=false;
           flag2=false;
           flag3=false;
           oppError=false;
           conError=false;
        }
        
        //if we select contact check box,then it displays contacts for selected accounts 
      if(conbox)
      {
      
              snts=[select id,lastName,Department,account.name from contact where accountid IN:acts];
              if(snts.size()>0)
              {
                  flag3=true;
                  conError=false;
              }
              else
              {
                  for(accountwrapper aw : actwrap) {
                      if(aw.acflag) {
                          flag3=true;
                          conError = true;
                      }
                          //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'contact records are not found for selected Accounts.'));
                    }
              }
         } else {
             flag3 = false;
         }
        //if we select opportunity check box,then it displays opportunities for selected accounts
      if(oppbox)
        {
              opts=[select id,name,stageName,leadsource,account.name from opportunity where accountId IN:acts];
              if(opts.size() >0)
              {
                  flag2=true;
                  oppError=false;
              }
              else       
              {    
                    for(accountwrapper aw : actwrap) {
                      if(aw.acflag) {
                          flag2=true;
                          oppError = true;
                      }
                          //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'opportunity records are not found for selected Accounts.'));
                    }
              }
        } else {
            flag2 = false;
        }
    }
   //it hides contacts and dispalys opportunitites on uncheck of contact check box
   //This method uses a simple SOQL query to return a List of Accounts
    public void getactwrap() {
        String QueryIf = '';
        string sortFullExp = sortExpression  + ' ' + sortDirection;
        if (AlphaFilter == null || AlphaFilter.trim().length() == 0) {
            AlphaFilter = 'All';
        }
        
        Query = 'SELECT Id, Name, phone ' + ' FROM Account'; 
        
        if (AlphaFilter == 'Other') {
            QueryIf = QueryFor(QueryIf, '(' + 'Name' + ' < \'A\' OR ' + 
                                    'Name' + ' > \'Z\') AND (NOT ' + 
                                    'Name' + ' LIKE \'Z%\') ');
        } else if (AlphaFilter != 'All') {
            QueryIf = QueryFor(QueryIf, '(' + 'Name' + ' LIKE \'' + String.escapeSingleQuotes(AlphaFilter) + '%\')' );
        }
        
        Query += QueryIf;
        Query += ' ORDER BY ' + sortFullExp + ' LIMIT : blockSize OFFSET : index';
        accounts = Database.Query(Query);
        actwrap=new list<accountwrapper>();
       // As each Account is processed we create a new accountwrapper object and add it to the wrapper class(accountwrapper) list.
         for(account a:accounts)
        {
            actwrap.add(new accountwrapper(a));
        }
        flag2=false;
        flag3=false;
        oppbox=false;
        conbox=false;
        checkallflag=false;
    }
    public String QueryFor(String Q, String C) {
        if (Q == '') {
            return ' WHERE ' + C;
        } else {
            return Q + ' AND ' + C;
        }
    }
    public void Hideandshowopp()
    {
     
        if(oppbox)
          {     
              submit();
          } else {
              flag2 = false;
          }
         
    }
   //  it hides opportunities and dispalys contacts on uncheck of opportunities check box 
     public void HideandshowCon()
    {
        if(conbox)
         {    
              submit();
          } else {
              flag3 = false;
          }
         
    }
   
    public void Hideandshowoppcon() {
        Hideandshowopp();
        Hideandshowcon();
    }
    
    
    // this method  uses dml operation to edit the existing opportunities values or to insert new oppt values
    public void saveopps()
    {
        list<opportunity> opps=new list<opportunity>();
        opps.addAll(opts);
        upsert opps;
    }
    //his method  uses dml operation to edit the existing contact values or to insert new contact values
    public void savecons()
    {
       cnts = new list<contact>();
        cnts.addall(snts);
        upsert cnts;
    }
 //This is wrapper class which is collection of other class instances
  //here  wrapper class contains both the standard salesforce object Account and a Boolean value acflag   
 public class accountwrapper{
        public account acc{set;get;}
        public boolean acflag{set;get;}
             //In this contructor When we create a new accountwrapper object we pass a Account that is set to the acc property.
             // We also set the boolean value to false
        public accountwrapper(account a){
            acc=a;
            acflag=false;
        }
        
    }

}
 
This was selected as the best answer
Siva@51Siva@51
page
=============================
<apex:page controller="Acc_con_Opp_Details" showHeader="false" docType="html-5.0">
    <style type="text/css">
    a.alpha-select {
       font-weight: bold;
       text-decoration: none;
       background-color: #C6E1FF;
       color: #000000 !important;
    }
    </style>
    <script>
    function checkallflag(allCheckboxes) {
    
        var container = allCheckboxes;
        while (container.tagName != "TABLE") {
            container = container.parentNode;
        }
    
        var inputs = container.getElementsByTagName("input");
        var checked = allCheckboxes.checked;
        for (var i = 0; i < inputs.length; i++) { 
            var input = inputs.item(i);
            if (input.type == "checkbox") {
                if (input != allCheckboxes) {
                    input.checked = checked;
                }
            }
        }
        CallSubmitMethod();
    }
    </script>
    <apex:form >
    <apex:actionFunction name="CallSubmitMethod" action="{!submit}"/>
    <!--This block dispalying account record details-->
    <apex:outputPanel id="par">
        
           
    <apex:pageblock id="par1" rendered="true">
        <apex:repeat value="{!AlphaList}" var="a">
          <apex:commandLink value="{!a}" action="{!getactwrap}" rerender="par1" styleClass="alpha-link{!if(AlphaFilter=a,' alpha-select','')}">
             <apex:param name="AlphaFilter" value="{!a}" assignTo="{!AlphaFilter}" />
             <!--<apex:actionSupport event="onchange" action="{!Reset}"/>-->
          </apex:commandLink>
          <apex:outputText >  |  </apex:outputText>
       </apex:repeat>
            
    <apex:pageMessages ></apex:pageMessages>
    <apex:pageblocktable value="{!actwrap}" var="a">
        <apex:column >
            <apex:facet name="header">
                <apex:inputCheckbox onclick="checkallflag(this)" value="{!checkallflag}"/>
            </apex:facet>
            <!--<apex:facet name="header">Select</apex:facet>-->
             <apex:inputCheckbox value="{!a.acflag}">
                 <apex:actionSupport event="onchange" action="{!Hideandshowoppcon}" reRender="par"/>
             </apex:inputCheckbox>
        </apex:column>
        <!-- displays id,name and phone number for accounts-->
        <apex:column value="{!a.acc.id}"/>
        <apex:column >
         <apex:facet name="header">   
           
           <apex:commandLink action="{!getactwrap}" value="Name{!IF(sortExpression=='name',IF(sortDirection='ASC','▼','▲'),'▼')}">
             <apex:param value="name" name="column" assignTo="{!sortExpression}"></apex:param>
           </apex:commandLink>
         </apex:facet>
         <apex:outputLabel >{!a.acc.Name}</apex:outputLabel>
       </apex:column>
        <apex:column value="{!a.acc.phone}"/>
         </apex:pageblocktable>
        <!-- this buttons are used to paginate account records-->
      
        <apex:pageblockButtons location="top">
            <!--displays first five records-->
            <apex:commandButton value="first"  action="{!beginning}" disabled="{!prev}"/>
            <!--displays previous records-->
            <apex:commandButton value="previous"  action="{!previous}" disabled="{!prev}"/>
             <!--displays previous  next records-->
            <apex:commandButton value="next"  action="{!next}" disabled="{!nxt}"/>
            <!-- displays last records-->
            <apex:commandButton value="last"  action="{!end}" disabled="{!nxt}"/>                                    
        </apex:pageblockButtons>
         <!-- check boxs for opportunities and contacts-->
       
     <center>  <apex:inputCheckbox value="{!oppbox}">
     <apex:actionSupport event="onchange" action="{!Hideandshowopp}"/>
     </apex:inputCheckbox>Opportunities&nbsp;&nbsp;&nbsp;
         <apex:inputCheckbox value="{!conbox}">
         <apex:actionSupport event="onchange" action="{!HideandshowCon}"/>
         </apex:inputCheckbox>Contacts&nbsp;&nbsp;&nbsp;
       <!-- <apex:commandButton value="submit" action="{!submit}"/>-->
       </center>
    </apex:pageblock>
    <!--this block displays opportunity details-->
    <apex:pageblock rendered="{!flag2}">
       
   <apex:pageblocktable value="{!opts}" var="o">
        <apex:column >
             <apex:facet name="header">Opportunity Id</apex:facet>
            <apex:commandlink value="{!o.id}" Action="{!URLFOR($Action.opportunity.edit,o.Id)}"/>
        </apex:column>
        <apex:column value="{!o.account.name}" />
        <apex:column >
            <apex:facet name="header">Opportunity Name</apex:facet>
       <apex:inputtext value="{!o.name}" />
            </apex:column>
        <apex:column >
           <apex:facet name="header">Opportunity Stage</apex:facet> 
       <apex:inputtext value="{!o.stagename}"/>
        </apex:column>
       <apex:column >
         <apex:facet name="header">Opportunity Leadsource</apex:facet> 
        </apex:column>
        </apex:pageblocktable>
        <apex:pageMessage rendered="{!oppError}" severity="error" strength="1" summary="No Opportunites Found" />
        <apex:commandButton value="Save Opportunities" action="{!saveopps}"/>
    </apex:pageblock>
             
    <!--this block is used for displaying contact details -->
            
     <apex:pageblock rendered="{!flag3}">
         
     <apex:pageblocktable value="{!snts}" var="c">
        <apex:column >
            <apex:facet name="header">Contact Id</apex:facet>
            <apex:commandlink value="{!c}" Action="{!URLFOR($Action.contact.edit,c)}"/>
        </apex:column>
         <apex:column value="{!c.account.name}" />
        <apex:column >
             <apex:facet name="header">Contact Lastname</apex:facet>
            <apex:inputtext value="{!c.lastname}"/>
        </apex:column>
        <apex:column >
        <apex:facet name="header">Contact Department</apex:facet>
            <apex:inputtext value="{!c.Department}"/>
        </apex:column>
        </apex:pageblocktable>
        <apex:pageMessage rendered="{!conError}" severity="error" strength="1" summary="No Contacts Found" /> 
         <apex:commandButton value="Save Contacts" action="{!savecons}" />
    </apex:pageblock>
        </apex:outputPanel>
    </apex:form>
</apex:page>

=====================================

Hope this helps you :)
anu deep 6anu deep 6
Hi siva,

Thanks for  your great support,code is working well.Please help me to fix following bugs in above code provided by you.

1.)With out selecting check boxs of account's record's if user clicks on opportunities/contacts check boxs then it should show error message that 'Choose atleast one account record to display opportunities' error message.Same is the case with contacts also.
User-added image

3.)If no opportunities/contacts records are found for the selected account records, it should not display save opportunities/contacts button.
     In above screen shot,you can observe that no opportunities are are found for selected accounts and it was displaying save opportunities button under opportunities table.we need to avoid that  save opportunities button,if no opportunities are found for selected accounts.

4.)Upon clicking on next button , column widths(positions) are not consistent.

    please help me by fixing above bugs in the code provided by you.
 
anu deep 6anu deep 6
HI siva,

I have successfully solved 2nd and 3rd bugs successfully,only 1st bug need to be solved.Please help me to resolve 1st bug.
 
Siva@51Siva@51

Anudeep,

In Class
=========================================
Modify the submit method as below 
===================================
Add these 2 at top of the class along with getters and setters
*************************************************
public Boolean oppboxError                    {set;get;}
public Boolean conboxError                    {set;get;}

****************************************************
"
"
"
"
"
public void  submit()
    {
        flag1=false;
        acts=new list<Account>();
        List<Boolean> acflagList = new List<Boolean>();
        for(accountwrapper aw:actwrap)
           {
            if(aw.acflag){
                acts.add(aw.acc);
                acflagList.add(aw.acflag);
           } 
        }
        if(acflagList.isEmpty()) {
           if(oppbox)
               oppboxError=true;
           if(conbox)
               conboxError=true;
           flag2=false;
           flag3=false;
           oppError=false;
           conError=false;
        } else {
            oppboxError=false;
            conboxError=false;
        }

        
        //if we select contact check box,then it displays contacts for selected accounts 
          '"
          "
          "
          "
======================================

In Page
========================================================
add the below code
"
"
"
"
"
</apex:inputCheckbox>Opportunities&nbsp;&nbsp;&nbsp;
         <apex:inputCheckbox value="{!conbox}">
         <apex:actionSupport event="onchange" action="{!HideandshowCon}"/>
         </apex:inputCheckbox>Contacts&nbsp;&nbsp;&nbsp;
       <!-- <apex:commandButton value="submit" action="{!submit}"/>-->
       </center>
       <apex:pageMessage rendered="{!oppboxError}" severity="error" strength="1" summary="Choose atleast one account record to display opportunities" /> 
       <apex:pageMessage rendered="{!conboxError}" severity="error" strength="1" summary="Choose atleast one account record to display contacts" /> 

    </apex:pageblock>
    <!--this block displays opportunity details-->
    <apex:pageblock rendered="{!flag2}">
 "
"
"
"
"
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

 

anu deep 6anu deep 6
HI siva,

Thanks for great support,I have solved almost all bugs with your help,Please help to achieve following enhancaments in the code.

I am also providing updated code.

1.If there are no accounts for a particular alphabet then it should show empty account table with "No Accounts Found" message and also first,prev,next,last buttons should be disabled as there are no records.

2.)Also put a text box component above the table and upon entering 3 or more letters then the corresponding accounts which contains the word should display. If user enters 1 or 2 letters then show error like please enter minimum 3 letters to search. If nothing is entered then no error should be displayed.

Apex controller
===========
public class Acc_con_Opp_Details
{
    //list of collection of the wrapper class object
    public list<accountwrapper> actwrap           {set;get;}
    //list of collection of Account,contact and opportunity objects
    public list<Account>        accounts          {set;get;}
    public list<Account>        acts              {set;get;}
    public list<opportunity>    opts              {set;get;}
    public list<opportunity>    sopts             {set;get;}
    public list<contact>        cnts              {set;get;} 
    public list<contact>        snts              {set;get;}
   public string                searchstring      {get;set;}//used in searching account records 
    public boolean oppbox                         {set;get;}//used as check box for opportunity 
    public boolean conbox                         {set;get;}//used as check box for contact
    public boolean flag1                          {set;get;}//used in account page block  
    public boolean flag2                          {set;get;}//used in contact page block 
    public boolean flag3                          {set;get;}//used in opportunity page block
    public boolean checkallflag                   {set;get;}//used for header check box
    public Boolean oppError                       {set;get;}//used to display opportunity error
    public Boolean conError                       {set;get;}//used to display contacts error
    public Boolean oppboxError                    {set;get;}//used to dispaly opportunity error
    public Boolean conboxError                    {set;get;}//used to display contacts error   
    public list<String> AlphaList                 {get; set;}//collection of alphabets
    public String AlphaFilter                     {get; set;}//used to filter alphabets
    private String Query;
    //this variables are used for pagination purpose
    private integer totalRecs = 0;//stores no.of total records   
    private integer index = 0;//used for tracking offset
    private integer blockSize =5;//for setting size of page
    private String sortDirection = 'ASC';
    private String sortExp = 'Name';
    public Map<String, String> mapAlpha{get; set;}
 
    //in this constructor we are setting values to boolean variables
    public Acc_con_Opp_Details()
    {
    flag1=true;
    flag2=false;
    flag3=false;
    oppError=false;
    conError=false;
    oppboxError=false;
    conboxError=false;    
    checkallflag = false;
    totalRecs = [select count() from Account];//returns total no.of account records 
    getactwrap();//calling getactwrap method.
    AlphaList = new list<String> {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'Other', 'All'};
    if (apexpages.currentpage().getparameters().get('alpha') == null) {
        AlphaFilter = 'All';
    } else {
        AlphaFilter = apexpages.currentpage().getparameters().get('alpha');
    }
    }
    public String sortExpression
    {
      get
      {
         return sortExp;
      }
      set
      {
        //if the column is clicked on then switch between Ascending and Descending modes
        if (value == sortExp)
          sortDirection = (sortDirection == 'ASC')? 'DESC' : 'ASC';
        else
          sortDirection = 'ASC';
          sortExp = value;
      }
    }

    public String getSortDirection()
    {
       //if not column is selected 
       if (sortExpression == null || sortExpression == '')
           return 'ASC';
       else
          return sortDirection;
    }

    public void setSortDirection(String value)
    {  
        sortDirection = value;
    }
    //this method displays first five records
    public void beginning()
    {    
        flag2 = false;
        flag3 = false;
        oppbox=false;
        conbox=false;
        conboxError=false;    
        oppboxError=false;
        checkallflag=false;
        index = 0;
        getactwrap();
    }
    //this method displays prevoius records
     public void previous()
    {    
        flag2 = false;
        flag3 = false;
        oppbox=false;
        conbox=false;
        conboxError=false;    
        oppboxError=false;
        checkallflag=false;
        index = index-blockSize;
        getactwrap();
    }
    //this method displays next records
   public void next()
    {    
        flag2 = false;
        flag3 = false;
        oppbox=false;
        conbox=false;
        conboxError=false;    
        oppboxError=false; 
        checkallflag=false;
        index = index+blockSize;
        getactwrap();
    }
    //this method displays last remaining records
 public void end()
    {    
        flag2 = false;
        flag3 = false;
        oppbox=false;
        conbox=false;
        conboxError=false;    
        oppboxError=false;
        checkallflag=false;
        index = totalrecs - math.mod(totalRecs,blockSize);
        getactwrap();
    }  
    //this variable is used to enable or disable first and previous buttons
 public boolean prev{get
    {
        if(index == 0)
        return true;
        else
        return false;
    }  set;}
    //this variable is used to enable or disable next and last buttons
 public boolean nxt{get
    {
        if((index + blockSize) > totalRecs)
        return true;
        else
        return false;
    }   set;}
    //used to display opportunities and contacts w.r.t selected accounts
    public void  submit()
    {
        
        acts=new list<Account>();
        List<Boolean> acflagList = new List<Boolean>();
        for(accountwrapper aw:actwrap)
           {
            if(aw.acflag){
                acts.add(aw.acc);
                acflagList.add(aw.acflag);
           } 
        }
        
         if(acflagList.isEmpty()) {
           if(oppbox)
               oppboxError=true;
           if(conbox)
               conboxError=true;
           flag2=false;
           flag3=false;
           oppError=false;
           conError=false;
        } 
        else 
        {
            oppboxError=false;
            conboxError=false;
        }
        
        //if we select contact check box,then it displays contacts for selected accounts 
      if(conbox)
      {
      
              snts=[select id,lastName,Department,account.name from contact where accountid IN:acts];
              if(snts.size()>0)
              {
                  flag3=true;
                  conError=false;
              }
              else
              {
                  for(accountwrapper aw : actwrap) {
                      if(aw.acflag) {
                          flag3=true;
                          conError = true;
                      }
                          //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'contact records are not found for selected Accounts.'));
                    }
              }
         } else {
             flag3 = false;
         }
        //if we select opportunity check box,then it displays opportunities for selected accounts
      if(oppbox)
        {
              opts=[select id,name,stageName,leadsource,account.name from opportunity where accountId IN:acts];
              if(opts.size() >0)
              {
                  flag2=true;
                  oppError=false;
              }
              else       
              {    
                    for(accountwrapper aw : actwrap) {
                      if(aw.acflag) {
                          flag2=true;
                          oppError = true;
                      }
                          //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'opportunity records are not found for selected Accounts.'));
                    }
              }
        } else {
            flag2 = false;
        }
        
    }
   //it hides contacts and dispalys opportunitites on uncheck of contact check box
   //This method uses a simple SOQL query to return a List of Accounts
    public void getactwrap() {
        String QueryIf = '';
        string sortFullExp = sortExpression  + ' ' + sortDirection;
        if (AlphaFilter == null || AlphaFilter.trim().length() == 0) {
            AlphaFilter = 'All';
        }
        
        Query = 'SELECT Id, Name, phone ' + ' FROM Account'; 
        
        if (AlphaFilter == 'Other') {
            QueryIf = QueryFor(QueryIf, '(' + 'Name' + ' < \'A\' OR ' + 
                                    'Name' + ' > \'Z\') AND (NOT ' + 
                                    'Name' + ' LIKE \'Z%\') ');
        } else if (AlphaFilter != 'All') {
            QueryIf = QueryFor(QueryIf, '(' + 'Name' + ' LIKE \'' + String.escapeSingleQuotes(AlphaFilter) + '%\')' );
        }
        
        Query += QueryIf;
        Query += ' ORDER BY ' + sortFullExp + ' LIMIT : blockSize OFFSET : index';
        accounts = Database.Query(Query);
        actwrap=new list<accountwrapper>();
       // As each Account is processed we create a new accountwrapper object and add it to the wrapper class(accountwrapper) list.
         for(account a:accounts)
        {
            actwrap.add(new accountwrapper(a));
        }
        flag2=false;
        flag3=false;
        oppbox=false;
        conbox=false;
        conboxError=false;    
        oppboxError=false;
        checkallflag=false;
    }
    public String QueryFor(String Q, String C) {
        if (Q == '') {
            return ' WHERE ' + C;
        } else {
            return Q + ' AND ' + C;
        }
    }
    public void Hideandshowopp()
    {
     
        if(oppbox)
          {     
              submit();
          } else {
              flag2 = false;
              oppboxError=false;
          }
         
    }
   //  it hides opportunities and dispalys contacts on uncheck of opportunities check box 
     public void HideandshowCon()
    {
        if(conbox)
         {    
              submit();
          } else {
              flag3 = false;
              conboxError=false;    
       
          }
         
    }
   
    public void Hideandshowoppcon() {
        Hideandshowopp();
        Hideandshowcon();
    }
    
    
    // this method  uses dml operation to edit the existing opportunities values or to insert new oppt values
    public void saveopps()
    {
        list<opportunity> opps=new list<opportunity>();
        opps.addAll(opts);
        upsert opps;
    }
    //his method  uses dml operation to edit the existing contact values or to insert new contact values
    public void savecons()
    {
       cnts = new list<contact>();
        cnts.addall(snts);
        upsert cnts;
    }
     //used for searching account records dynamically
     public void search(){  
     string searchquery='select name,id from account where name like \'%'+searchstring+'%\' Limit 20';  
     accounts= Database.query(searchquery);  
   }  
 //This is wrapper class which is collection of other class instances
  //here  wrapper class contains both the standard salesforce object Account and a Boolean value acflag   
 public class accountwrapper{
        public account acc{set;get;}
        public boolean acflag{set;get;}
             //In this contructor When we create a new accountwrapper object we pass a Account that is set to the acc property.
             // We also set the boolean value to false
        public accountwrapper(account a){
            acc=a;
            acflag=false;
        }
        
    }

}

NOTE:-FIND VISUAL FORCE PAGE IN BELOW POST
anu deep 6anu deep 6
HI Siva,
vf page
=====
<apex:page controller="Acc_con_Opp_Details" showHeader="false" docType="html-5.0">
    <style type="text/css">
    a.alpha-select 
    {
       font-weight: bold;
       text-decoration: none;
       background-color: #C6E1FF;
       color: #000000 !important;
    }
    </style>
    <script>
    function checkallflag(allCheckboxes)
    {
    
        var container = allCheckboxes;
        while (container.tagName != "TABLE") {
            container = container.parentNode;
        }
    
        var inputs = container.getElementsByTagName("input");
        var checked = allCheckboxes.checked;
        for (var i = 0; i < inputs.length; i++) { 
            var input = inputs.item(i);
            if (input.type == "checkbox") {
                if (input != allCheckboxes) {
                    input.checked = checked;
                }
            }
        }
        CallSubmitMethod();
    }
    </script>
    <apex:form >
    <apex:actionFunction name="CallSubmitMethod" action="{!submit}"/>
    <!--This block dispalying account record details-->
    <apex:outputPanel id="par">
      
           
    <apex:pageblock id="par1" rendered="true">
           &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; enter:<apex:inputText value="{!searchstring}"/> 
         &nbsp;&nbsp;&nbsp;<apex:commandButton value="Search records" action="{!search}"/>  
        <br/><br/> <apex:repeat value="{!AlphaList}" var="a">
          <apex:commandLink value="{!a}" action="{!getactwrap}" rerender="par1" styleClass="alpha-link{!if(AlphaFilter=a,' alpha-select','')}">
             <apex:param name="AlphaFilter" value="{!a}" assignTo="{!AlphaFilter}" />
             <!--<apex:actionSupport event="onchange" action="{!Reset}"/>-->
          </apex:commandLink>
          <apex:outputText >  |  </apex:outputText>
       </apex:repeat>
            
    <apex:pageMessages ></apex:pageMessages>
    <apex:pageblocktable value="{!actwrap}" var="a">
        <apex:column >
            <apex:facet name="header">
                <apex:inputCheckbox onclick="checkallflag(this)" value="{!checkallflag}"/>
            </apex:facet>
            <!--<apex:facet name="header">Select</apex:facet>-->
             <apex:inputCheckbox value="{!a.acflag}">
                 <apex:actionSupport event="onchange" action="{!Hideandshowoppcon}" reRender="par"/>
             </apex:inputCheckbox>
        </apex:column>
        <!-- displays id,name and phone number for accounts-->
        <apex:column value="{!a.acc.id}" width="30%"/>
        <apex:column width="50%">
         <apex:facet name="header">   
           
           <apex:commandLink action="{!getactwrap}" value="Name{!IF(sortExpression=='name',IF(sortDirection='ASC','▼','▲'),'▼')}">
             <apex:param value="name" name="column" assignTo="{!sortExpression}"></apex:param>
           </apex:commandLink>
         </apex:facet>
         <apex:outputLabel >{!a.acc.Name}</apex:outputLabel>
       </apex:column>
        <apex:column value="{!a.acc.phone}" width="50%"/>
         </apex:pageblocktable>
        <!-- this buttons are used to paginate account records-->
      
        <apex:pageblockButtons location="top">
            <!--displays first five records-->
            <apex:commandButton value="first"  action="{!beginning}" disabled="{!prev}" style="height:22px;width:57px;"/>
            <!--displays previous records-->
            <apex:commandButton value="previous"  action="{!previous}" disabled="{!prev}" style="height:22px;width:57px;"/>
             <!--displays previous  next records-->
            <apex:commandButton value="next"  action="{!next}" disabled="{!nxt}" style="height:22px;width:57px;"/>
            <!-- displays last records-->
            <apex:commandButton value="last"  action="{!end}" disabled="{!nxt}" style="height:23px;width:57px;"/>                                    
        </apex:pageblockButtons>
         <!-- check boxs for opportunities and contacts-->
       
     <center>  <apex:inputCheckbox value="{!oppbox}">
     <apex:actionSupport event="onchange" action="{!Hideandshowopp}"/>
     </apex:inputCheckbox>Opportunities&nbsp;&nbsp;&nbsp;
 
         <apex:inputCheckbox value="{!conbox}">
         <apex:actionSupport event="onchange" action="{!HideandshowCon}"/>
         </apex:inputCheckbox>Contacts&nbsp;&nbsp;&nbsp;
 
       <!-- <apex:commandButton value="submit" action="{!submit}"/>-->
       </center>
         <apex:pageMessage rendered="{!oppboxError}" severity="error" strength="1" summary="Choose atleast one account record to display opportunities" />
          <apex:pageMessage rendered="{!conboxError}" severity="error" strength="1" summary="Choose atleast one account record to display contacts" /> 
    </apex:pageblock>
        
    <!--this block displays opportunity details-->
    <apex:pageblock rendered="{!flag2}">
       
   <apex:pageblocktable value="{!opts}" var="o">
        <apex:column >
             <apex:facet name="header">Opportunity Id</apex:facet>
            <apex:commandlink value="{!o.id}" Action="{!URLFOR($Action.opportunity.edit,o.Id)}"/>
        </apex:column>
        <apex:column value="{!o.account.name}" />
        <apex:column >
            <apex:facet name="header">Opportunity Name</apex:facet>
       <apex:inputtext value="{!o.name}" />
            </apex:column>
        <apex:column >
           <apex:facet name="header">Opportunity Stage</apex:facet> 
       <apex:inputtext value="{!o.stagename}"/>
        </apex:column>
       <apex:column >
         <apex:facet name="header">Opportunity Leadsource</apex:facet> 
        </apex:column>
        </apex:pageblocktable>
        <apex:pageMessage rendered="{!oppError}" severity="error" strength="1" summary="No Opportunites Found" />
        <apex:commandButton value="Save Opportunities" action="{!saveopps}" rendered="{!opts.size !=0}"/>

    </apex:pageblock>
             
    <!--this block is used for displaying contact details -->
            
     <apex:pageblock rendered="{!flag3}">
         
     <apex:pageblocktable value="{!snts}" var="c">
        <apex:column >
            <apex:facet name="header">Contact Id</apex:facet>
            <apex:commandlink value="{!c}" Action="{!URLFOR($Action.contact.edit,c)}"/>
        </apex:column>
         <apex:column value="{!c.account.name}" />
        <apex:column >
             <apex:facet name="header">Contact Lastname</apex:facet>
            <apex:inputtext value="{!c.lastname}"/>
        </apex:column>
        <apex:column >
        <apex:facet name="header">Contact Department</apex:facet>
            <apex:inputtext value="{!c.Department}"/>
        </apex:column>
        </apex:pageblocktable>
        <apex:pageMessage rendered="{!conError}" severity="error" strength="1" summary="No Contacts Found" /> 
         <apex:commandButton value="Save Contacts" action="{!savecons}" rendered="{!snts.size !=0}"/>
    </apex:pageblock>
        </apex:outputPanel>
    </apex:form>
</apex:page>
anu deep 6anu deep 6
Hi siva,

I am waiting for your reply.Kindly help me
Siva@51Siva@51
Anudeep,
Sorry, I didnot get your question. You have just pasted VF page right? What is your question in it?
 
anu deep 6anu deep 6
Hi siva,

I have mentioned questions in  the post whcich is above to the vf page post.Due to size limitation i am unable to post all the things in single post.So,I posted questions and apex controller in one post,vf page in another post.Sorry for confusing you.I here by providing questions again,

following  are the enhancements need to be done in the below code
=================================================

1.)If there are no accounts for a particular alphabet then it should show empty account table with "No Accounts Found" message and also first,prev,next,last buttons should be disabled as there are no records.

2.)Also put a text box component above the table and upon entering 3 or more letters then the corresponding accounts which contains the word should display. If user enters 1 or 2 letters then show error like please enter minimum 3 letters to search. If nothing is entered then no error should be displayed.

apex controller
===========
public class Acc_con_Opp_Details
{
    //list of collection of the wrapper class object
    public list<accountwrapper> actwrap           {set;get;}
    //list of collection of Account,contact and opportunity objects
    public list<Account>        accounts          {set;get;}
    public list<Account>        acts              {set;get;}
    public list<opportunity>    opts              {set;get;}
    public list<opportunity>    sopts             {set;get;}
    public list<contact>        cnts              {set;get;} 
    public list<contact>        snts              {set;get;}
   public string                searchstring      {get;set;}//used in searching account records 
    public boolean oppbox                         {set;get;}//used as check box for opportunity 
    public boolean conbox                         {set;get;}//used as check box for contact
    public boolean flag1                          {set;get;}//used in account page block  
    public boolean flag2                          {set;get;}//used in contact page block 
    public boolean flag3                          {set;get;}//used in opportunity page block
    public boolean checkallflag                   {set;get;}//used for header check box
    public Boolean oppError                       {set;get;}//used to display opportunity error
    public Boolean conError                       {set;get;}//used to display contacts error
    public Boolean oppboxError                    {set;get;}//used to dispaly opportunity error
    public Boolean conboxError                    {set;get;}//used to display contacts error   
    public list<String> AlphaList                 {get; set;}//collection of alphabets
    public String AlphaFilter                     {get; set;}//used to filter alphabets
    private String Query;
    //this variables are used for pagination purpose
    private integer totalRecs = 0;//stores no.of total records   
    private integer index = 0;//used for tracking offset
    private integer blockSize =5;//for setting size of page
    private String sortDirection = 'ASC';
    private String sortExp = 'Name';
    public Map<String, String> mapAlpha{get; set;}
 
    //in this constructor we are setting values to boolean variables
    public Acc_con_Opp_Details()
    {
    flag1=true;
    flag2=false;
    flag3=false;
    oppError=false;
    conError=false;
    oppboxError=false;
    conboxError=false;    
    checkallflag = false;
    totalRecs = [select count() from Account];//returns total no.of account records 
    getactwrap();//calling getactwrap method.
    AlphaList = new list<String> {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'Other', 'All'};
    if (apexpages.currentpage().getparameters().get('alpha') == null) {
        AlphaFilter = 'All';
    } else {
        AlphaFilter = apexpages.currentpage().getparameters().get('alpha');
    }
    }
    public String sortExpression
    {
      get
      {
         return sortExp;
      }
      set
      {
        //if the column is clicked on then switch between Ascending and Descending modes
        if (value == sortExp)
          sortDirection = (sortDirection == 'ASC')? 'DESC' : 'ASC';
        else
          sortDirection = 'ASC';
          sortExp = value;
      }
    }

    public String getSortDirection()
    {
       //if not column is selected 
       if (sortExpression == null || sortExpression == '')
           return 'ASC';
       else
          return sortDirection;
    }

    public void setSortDirection(String value)
    {  
        sortDirection = value;
    }
    //this method displays first five records
    public void beginning()
    {    
        flag2 = false;
        flag3 = false;
        oppbox=false;
        conbox=false;
        conboxError=false;    
        oppboxError=false;
        checkallflag=false;
        index = 0;
        getactwrap();
    }
    //this method displays prevoius records
     public void previous()
    {    
        flag2 = false;
        flag3 = false;
        oppbox=false;
        conbox=false;
        conboxError=false;    
        oppboxError=false;
        checkallflag=false;
        index = index-blockSize;
        getactwrap();
    }
    //this method displays next records
   public void next()
    {    
        flag2 = false;
        flag3 = false;
        oppbox=false;
        conbox=false;
        conboxError=false;    
        oppboxError=false; 
        checkallflag=false;
        index = index+blockSize;
        getactwrap();
    }
    //this method displays last remaining records
 public void end()
    {    
        flag2 = false;
        flag3 = false;
        oppbox=false;
        conbox=false;
        conboxError=false;    
        oppboxError=false;
        checkallflag=false;
        index = totalrecs - math.mod(totalRecs,blockSize);
        getactwrap();
    }  
    //this variable is used to enable or disable first and previous buttons
 public boolean prev{get
    {
        if(index == 0)
        return true;
        else
        return false;
    }  set;}
    //this variable is used to enable or disable next and last buttons
 public boolean nxt{get
    {
        if((index + blockSize) > totalRecs)
        return true;
        else
        return false;
    }   set;}
    //used to display opportunities and contacts w.r.t selected accounts
    public void  submit()
    {
        
        acts=new list<Account>();
        List<Boolean> acflagList = new List<Boolean>();
        for(accountwrapper aw:actwrap)
           {
            if(aw.acflag){
                acts.add(aw.acc);
                acflagList.add(aw.acflag);
           } 
        }
        
         if(acflagList.isEmpty()) {
           if(oppbox)
               oppboxError=true;
           if(conbox)
               conboxError=true;
           flag2=false;
           flag3=false;
           oppError=false;
           conError=false;
        } 
        else 
        {
            oppboxError=false;
            conboxError=false;
        }
        
        //if we select contact check box,then it displays contacts for selected accounts 
      if(conbox)
      {
      
              snts=[select id,lastName,Department,account.name from contact where accountid IN:acts];
              if(snts.size()>0)
              {
                  flag3=true;
                  conError=false;
              }
              else
              {
                  for(accountwrapper aw : actwrap) {
                      if(aw.acflag) {
                          flag3=true;
                          conError = true;
                      }
                          //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'contact records are not found for selected Accounts.'));
                    }
              }
         } else {
             flag3 = false;
         }
        //if we select opportunity check box,then it displays opportunities for selected accounts
      if(oppbox)
        {
              opts=[select id,name,stageName,leadsource,account.name from opportunity where accountId IN:acts];
              if(opts.size() >0)
              {
                  flag2=true;
                  oppError=false;
              }
              else       
              {    
                    for(accountwrapper aw : actwrap) {
                      if(aw.acflag) {
                          flag2=true;
                          oppError = true;
                      }
                          //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'opportunity records are not found for selected Accounts.'));
                    }
              }
        } else {
            flag2 = false;
        }
        
    }
   //it hides contacts and dispalys opportunitites on uncheck of contact check box
   //This method uses a simple SOQL query to return a List of Accounts
    public void getactwrap() {
        String QueryIf = '';
        string sortFullExp = sortExpression  + ' ' + sortDirection;
        if (AlphaFilter == null || AlphaFilter.trim().length() == 0) {
            AlphaFilter = 'All';
        }
        
        Query = 'SELECT Id, Name, phone ' + ' FROM Account'; 
        
        if (AlphaFilter == 'Other') {
            QueryIf = QueryFor(QueryIf, '(' + 'Name' + ' < \'A\' OR ' + 
                                    'Name' + ' > \'Z\') AND (NOT ' + 
                                    'Name' + ' LIKE \'Z%\') ');
        } else if (AlphaFilter != 'All') {
            QueryIf = QueryFor(QueryIf, '(' + 'Name' + ' LIKE \'' + String.escapeSingleQuotes(AlphaFilter) + '%\')' );
        }
        
        Query += QueryIf;
        Query += ' ORDER BY ' + sortFullExp + ' LIMIT : blockSize OFFSET : index';
        accounts = Database.Query(Query);
        actwrap=new list<accountwrapper>();
       // As each Account is processed we create a new accountwrapper object and add it to the wrapper class(accountwrapper) list.
         for(account a:accounts)
        {
            actwrap.add(new accountwrapper(a));
        }
        flag2=false;
        flag3=false;
        oppbox=false;
        conbox=false;
        conboxError=false;    
        oppboxError=false;
        checkallflag=false;
    }
    public String QueryFor(String Q, String C) {
        if (Q == '') {
            return ' WHERE ' + C;
        } else {
            return Q + ' AND ' + C;
        }
    }
    public void Hideandshowopp()
    {
     
        if(oppbox)
          {     
              submit();
          } else {
              flag2 = false;
              oppboxError=false;
          }
         
    }
   //  it hides opportunities and dispalys contacts on uncheck of opportunities check box 
     public void HideandshowCon()
    {
        if(conbox)
         {    
              submit();
          } else {
              flag3 = false;
              conboxError=false;    
       
          }
         
    }
   
    public void Hideandshowoppcon() {
        Hideandshowopp();
        Hideandshowcon();
    }
    
    
    // this method  uses dml operation to edit the existing opportunities values or to insert new oppt values
    public void saveopps()
    {
        list<opportunity> opps=new list<opportunity>();
        opps.addAll(opts);
        upsert opps;
    }
    //his method  uses dml operation to edit the existing contact values or to insert new contact values
    public void savecons()
    {
       cnts = new list<contact>();
        cnts.addall(snts);
        upsert cnts;
    }
     //used for searching account records dynamically
     public void search(){  
     string searchquery='select name,id from account where name like \'%'+searchstring+'%\' Limit 20';  
     accounts= Database.query(searchquery);  
   }  
 //This is wrapper class which is collection of other class instances
  //here  wrapper class contains both the standard salesforce object Account and a Boolean value acflag   
 public class accountwrapper{
        public account acc{set;get;}
        public boolean acflag{set;get;}
             //In this contructor When we create a new accountwrapper object we pass a Account that is set to the acc property.
             // We also set the boolean value to false
        public accountwrapper(account a){
            acc=a;
            acflag=false;
        }
        
    }

}
 
NOTE:YOU CAN FIND VF PAGE IN ABOVE POST.
anu deep 6anu deep 6
HI siva,

I am waiting for your respones,Kindly please help me.
anu deep 6anu deep 6
Hi siva,

I am waiting for your reply,Please help me. 
Siva@51Siva@51
This thread is too much prolonging.
Can you please close this thread, marking any of the answer as the best which resolves your issue the most?
Don't worry about your other issues. Open it in new thread and copy that link in this thread comments. I will look into it.
Thanks :)
anu deep 6anu deep 6
Hi siva,

As per your advice I am closing this thread and opening it in new thread,Please look into it.Thanks for the great support.

NOTE:The title of new thread will be "VISUAL FORCE PAGE ISSUES".
Siva@51Siva@51
Anudeep,
I didnot find any thread with the mentioned name. Can you please paste the URL.
Thanks :)
anu deep 6anu deep 6
Hi siva,

As per your advice,I am trying to start new thread from this morning.But it was throwing an error

Uncaught TypeError: Cannot read property 'setParams' of undefined throws at https://developer.salesforce.com/forums/?id=9060G000000XbTBQA0:1314:42 

I tried with different developer accounts,but it was giving same error.I think there was problem with salesforce community forum.
Once it was solved I will start new thread.Meanwhile let us use same thread.please solve below issues as soon as possible.

1.If there are no accounts for a particular alphabet then it should show empty account table with "No Accounts Found" message and also first,prev,next,last buttons should be disabled as there are no records.

2.)Also put a text box component above the table and upon entering 3 or more letters then the corresponding accounts which contains the word should display. If user enters 1 or 2 letters then show error like please enter minimum 3 letters to search. If nothing is entered then no error should be displayed.

Below is code
=========

apex controller
===========

public class Acc_con_Opp_Details
{
    //list of collection of the wrapper class object
    public list<accountwrapper> actwrap           {set;get;}
    //list of collection of Account,contact and opportunity objects
    public list<Account>        accounts          {set;get;}
    public list<Account>        acts              {set;get;}
    public list<opportunity>    opts              {set;get;}
    public list<opportunity>    sopts             {set;get;}
    public list<contact>        cnts              {set;get;} 
    public list<contact>        snts              {set;get;}
   public string                searchstring      {get;set;}//used in searching account records 
    public boolean oppbox                         {set;get;}//used as check box for opportunity 
    public boolean conbox                         {set;get;}//used as check box for contact
    public boolean flag1                          {set;get;}//used in account page block  
    public boolean flag2                          {set;get;}//used in contact page block 
    public boolean flag3                          {set;get;}//used in opportunity page block
    public boolean checkallflag                   {set;get;}//used for header check box
    public Boolean oppError                       {set;get;}//used to display opportunity error
    public Boolean conError                       {set;get;}//used to display contacts error
    public Boolean oppboxError                    {set;get;}//used to dispaly opportunity error
    public Boolean conboxError                    {set;get;}//used to display contacts error   
    public list<String> AlphaList                 {get; set;}//collection of alphabets
    public String AlphaFilter                     {get; set;}//used to filter alphabets
    private String Query;
    //this variables are used for pagination purpose
    private integer totalRecs = 0;//stores no.of total records   
    private integer index = 0;//used for tracking offset
    private integer blockSize =5;//for setting size of page
    private String sortDirection = 'ASC';
    private String sortExp = 'Name';
    public Map<String, String> mapAlpha{get; set;}
 
    //in this constructor we are setting values to boolean variables
    public Acc_con_Opp_Details()
    {
    flag1=true;
    flag2=false;
    flag3=false;
    oppError=false;
    conError=false;
    oppboxError=false;
    conboxError=false;    
    checkallflag = false;
    totalRecs = [select count() from Account];//returns total no.of account records 
    getactwrap();//calling getactwrap method.
    AlphaList = new list<String> {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'Other', 'All'};
    if (apexpages.currentpage().getparameters().get('alpha') == null) {
        AlphaFilter = 'All';
    } else {
        AlphaFilter = apexpages.currentpage().getparameters().get('alpha');
    }
    }
    public String sortExpression
    {
      get
      {
         return sortExp;
      }
      set
      {
        //if the column is clicked on then switch between Ascending and Descending modes
        if (value == sortExp)
          sortDirection = (sortDirection == 'ASC')? 'DESC' : 'ASC';
        else
          sortDirection = 'ASC';
          sortExp = value;
      }
    }

    public String getSortDirection()
    {
       //if not column is selected 
       if (sortExpression == null || sortExpression == '')
           return 'ASC';
       else
          return sortDirection;
    }

    public void setSortDirection(String value)
    {  
        sortDirection = value;
    }
    //this method displays first five records
    public void beginning()
    {    
        flag2 = false;
        flag3 = false;
        oppbox=false;
        conbox=false;
        conboxError=false;    
        oppboxError=false;
        checkallflag=false;
        index = 0;
        getactwrap();
    }
    //this method displays prevoius records
     public void previous()
    {    
        flag2 = false;
        flag3 = false;
        oppbox=false;
        conbox=false;
        conboxError=false;    
        oppboxError=false;
        checkallflag=false;
        index = index-blockSize;
        getactwrap();
    }
    //this method displays next records
   public void next()
    {    
        flag2 = false;
        flag3 = false;
        oppbox=false;
        conbox=false;
        conboxError=false;    
        oppboxError=false; 
        checkallflag=false;
        index = index+blockSize;
        getactwrap();
    }
    //this method displays last remaining records
 public void end()
    {    
        flag2 = false;
        flag3 = false;
        oppbox=false;
        conbox=false;
        conboxError=false;    
        oppboxError=false;
        checkallflag=false;
        index = totalrecs - math.mod(totalRecs,blockSize);
        getactwrap();
    }  
    //this variable is used to enable or disable first and previous buttons
 public boolean prev{get
    {
        if(index == 0)
        return true;
        else
        return false;
    }  set;}
    //this variable is used to enable or disable next and last buttons
 public boolean nxt{get
    {
        if((index + blockSize) > totalRecs)
        return true;
        else
        return false;
    }   set;}
    //used to display opportunities and contacts w.r.t selected accounts
    public void  submit()
    {
        
        acts=new list<Account>();
        List<Boolean> acflagList = new List<Boolean>();
        for(accountwrapper aw:actwrap)
           {
            if(aw.acflag){
                acts.add(aw.acc);
                acflagList.add(aw.acflag);
           } 
        }
        
         if(acflagList.isEmpty()) {
           if(oppbox)
               oppboxError=true;
           if(conbox)
               conboxError=true;
           flag2=false;
           flag3=false;
           oppError=false;
           conError=false;
        } 
        else 
        {
            oppboxError=false;
            conboxError=false;
        }
        
        //if we select contact check box,then it displays contacts for selected accounts 
      if(conbox)
      {
      
              snts=[select id,lastName,Department,account.name from contact where accountid IN:acts];
              if(snts.size()>0)
              {
                  flag3=true;
                  conError=false;
              }
              else
              {
                  for(accountwrapper aw : actwrap) {
                      if(aw.acflag) {
                          flag3=true;
                          conError = true;
                      }
                          //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'contact records are not found for selected Accounts.'));
                    }
              }
         } else {
             flag3 = false;
         }
        //if we select opportunity check box,then it displays opportunities for selected accounts
      if(oppbox)
        {
              opts=[select id,name,stageName,leadsource,account.name from opportunity where accountId IN:acts];
              if(opts.size() >0)
              {
                  flag2=true;
                  oppError=false;
              }
              else       
              {    
                    for(accountwrapper aw : actwrap) {
                      if(aw.acflag) {
                          flag2=true;
                          oppError = true;
                      }
                          //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'opportunity records are not found for selected Accounts.'));
                    }
              }
        } else {
            flag2 = false;
        }
        
    }
   //it hides contacts and dispalys opportunitites on uncheck of contact check box
   //This method uses a simple SOQL query to return a List of Accounts
    public void getactwrap() {
        String QueryIf = '';
        string sortFullExp = sortExpression  + ' ' + sortDirection;
        if (AlphaFilter == null || AlphaFilter.trim().length() == 0) {
            AlphaFilter = 'All';
        }
        
        Query = 'SELECT Id, Name, phone ' + ' FROM Account'; 
        
        if (AlphaFilter == 'Other') {
            QueryIf = QueryFor(QueryIf, '(' + 'Name' + ' < \'A\' OR ' + 
                                    'Name' + ' > \'Z\') AND (NOT ' + 
                                    'Name' + ' LIKE \'Z%\') ');
        } else if (AlphaFilter != 'All') {
            QueryIf = QueryFor(QueryIf, '(' + 'Name' + ' LIKE \'' + String.escapeSingleQuotes(AlphaFilter) + '%\')' );
        }
        
        Query += QueryIf;
        Query += ' ORDER BY ' + sortFullExp + ' LIMIT : blockSize OFFSET : index';
        accounts = Database.Query(Query);
        actwrap=new list<accountwrapper>();
       // As each Account is processed we create a new accountwrapper object and add it to the wrapper class(accountwrapper) list.
         for(account a:accounts)
        {
            actwrap.add(new accountwrapper(a));
        }
        flag2=false;
        flag3=false;
        oppbox=false;
        conbox=false;
        conboxError=false;    
        oppboxError=false;
        checkallflag=false;
    }
    public String QueryFor(String Q, String C) {
        if (Q == '') {
            return ' WHERE ' + C;
        } else {
            return Q + ' AND ' + C;
        }
    }
    public void Hideandshowopp()
    {
     
        if(oppbox)
          {     
              submit();
          } else {
              flag2 = false;
              oppboxError=false;
          }
         
    }
   //  it hides opportunities and dispalys contacts on uncheck of opportunities check box 
     public void HideandshowCon()
    {
        if(conbox)
         {    
              submit();
          } else {
              flag3 = false;
              conboxError=false;    
       
          }
         
    }
   
    public void Hideandshowoppcon() {
        Hideandshowopp();
        Hideandshowcon();
    }
    
    
    // this method  uses dml operation to edit the existing opportunities values or to insert new oppt values
    public void saveopps()
    {
        list<opportunity> opps=new list<opportunity>();
        opps.addAll(opts);
        upsert opps;
    }
    //his method  uses dml operation to edit the existing contact values or to insert new contact values
    public void savecons()
    {
       cnts = new list<contact>();
        cnts.addall(snts);
        upsert cnts;
    }
     //used for searching account records dynamically
     public void search(){  
     string searchquery='select name,id from account where name like \'%'+searchstring+'%\' Limit 20';  
     accounts= Database.query(searchquery);  
   }  
 //This is wrapper class which is collection of other class instances
  //here  wrapper class contains both the standard salesforce object Account and a Boolean value acflag   
 public class accountwrapper{
        public account acc{set;get;}
        public boolean acflag{set;get;}
             //In this contructor When we create a new accountwrapper object we pass a Account that is set to the acc property.
             // We also set the boolean value to false
        public accountwrapper(account a){
            acc=a;
            acflag=false;
        }
        
    }

}

NOTE:-Please find VF page in below page
===============================

 
anu deep 6anu deep 6
Hi siva,
 
In above post you can find apex controller.

Below is VF page.

VF PAGE
=======

<apex:page controller="Acc_con_Opp_Details" showHeader="false" docType="html-5.0">
    <style type="text/css">
    a.alpha-select 
    {
       font-weight: bold;
       text-decoration: none;
       background-color: #C6E1FF;
       color: #000000 !important;
    }
    </style>
    <script>
    function checkallflag(allCheckboxes)
    {
    
        var container = allCheckboxes;
        while (container.tagName != "TABLE") {
            container = container.parentNode;
        }
    
        var inputs = container.getElementsByTagName("input");
        var checked = allCheckboxes.checked;
        for (var i = 0; i < inputs.length; i++) { 
            var input = inputs.item(i);
            if (input.type == "checkbox") {
                if (input != allCheckboxes) {
                    input.checked = checked;
                }
            }
        }
        CallSubmitMethod();
    }
    </script>
    <apex:form >
    <apex:actionFunction name="CallSubmitMethod" action="{!submit}"/>
    <!--This block dispalying account record details-->
    <apex:outputPanel id="par">
      
           
    <apex:pageblock id="par1" rendered="true">
           &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; enter:<apex:inputText value="{!searchstring}"/> 
         &nbsp;&nbsp;&nbsp;<apex:commandButton value="Search records" action="{!search}"/>  
        <br/><br/> <apex:repeat value="{!AlphaList}" var="a">
          <apex:commandLink value="{!a}" action="{!getactwrap}" rerender="par1" styleClass="alpha-link{!if(AlphaFilter=a,' alpha-select','')}">
             <apex:param name="AlphaFilter" value="{!a}" assignTo="{!AlphaFilter}" />
             <!--<apex:actionSupport event="onchange" action="{!Reset}"/>-->
          </apex:commandLink>
          <apex:outputText >  |  </apex:outputText>
       </apex:repeat>
            
    <apex:pageMessages ></apex:pageMessages>
    <apex:pageblocktable value="{!actwrap}" var="a">
        <apex:column >
            <apex:facet name="header">
                <apex:inputCheckbox onclick="checkallflag(this)" value="{!checkallflag}"/>
            </apex:facet>
            <!--<apex:facet name="header">Select</apex:facet>-->
             <apex:inputCheckbox value="{!a.acflag}">
                 <apex:actionSupport event="onchange" action="{!Hideandshowoppcon}" reRender="par"/>
             </apex:inputCheckbox>
        </apex:column>
        <!-- displays id,name and phone number for accounts-->
        <apex:column value="{!a.acc.id}" width="30%"/>
        <apex:column width="50%">
         <apex:facet name="header">   
           
           <apex:commandLink action="{!getactwrap}" value="Name{!IF(sortExpression=='name',IF(sortDirection='ASC','▼','▲'),'▼')}">
             <apex:param value="name" name="column" assignTo="{!sortExpression}"></apex:param>
           </apex:commandLink>
         </apex:facet>
         <apex:outputLabel >{!a.acc.Name}</apex:outputLabel>
       </apex:column>
        <apex:column value="{!a.acc.phone}" width="50%"/>
         </apex:pageblocktable>
        <!-- this buttons are used to paginate account records-->
      
        <apex:pageblockButtons location="top">
            <!--displays first five records-->
            <apex:commandButton value="first"  action="{!beginning}" disabled="{!prev}" style="height:22px;width:57px;"/>
            <!--displays previous records-->
            <apex:commandButton value="previous"  action="{!previous}" disabled="{!prev}" style="height:22px;width:57px;"/>
             <!--displays previous  next records-->
            <apex:commandButton value="next"  action="{!next}" disabled="{!nxt}" style="height:22px;width:57px;"/>
            <!-- displays last records-->
            <apex:commandButton value="last"  action="{!end}" disabled="{!nxt}" style="height:23px;width:57px;"/>                                    
        </apex:pageblockButtons>
         <!-- check boxs for opportunities and contacts-->
       
     <center>  <apex:inputCheckbox value="{!oppbox}">
     <apex:actionSupport event="onchange" action="{!Hideandshowopp}"/>
     </apex:inputCheckbox>Opportunities&nbsp;&nbsp;&nbsp;
 
         <apex:inputCheckbox value="{!conbox}">
         <apex:actionSupport event="onchange" action="{!HideandshowCon}"/>
         </apex:inputCheckbox>Contacts&nbsp;&nbsp;&nbsp;
 
       <!-- <apex:commandButton value="submit" action="{!submit}"/>-->
       </center>
         <apex:pageMessage rendered="{!oppboxError}" severity="error" strength="1" summary="Choose atleast one account record to display opportunities" />
          <apex:pageMessage rendered="{!conboxError}" severity="error" strength="1" summary="Choose atleast one account record to display contacts" /> 
    </apex:pageblock>
        
    <!--this block displays opportunity details-->
    <apex:pageblock rendered="{!flag2}">
       
   <apex:pageblocktable value="{!opts}" var="o">
        <apex:column >
             <apex:facet name="header">Opportunity Id</apex:facet>
            <apex:commandlink value="{!o.id}" Action="{!URLFOR($Action.opportunity.edit,o.Id)}"/>
        </apex:column>
        <apex:column value="{!o.account.name}" />
        <apex:column >
            <apex:facet name="header">Opportunity Name</apex:facet>
       <apex:inputtext value="{!o.name}" />
            </apex:column>
        <apex:column >
           <apex:facet name="header">Opportunity Stage</apex:facet> 
       <apex:inputtext value="{!o.stagename}"/>
        </apex:column>
       <apex:column >
         <apex:facet name="header">Opportunity Leadsource</apex:facet> 
        </apex:column>
        </apex:pageblocktable>
        <apex:pageMessage rendered="{!oppError}" severity="error" strength="1" summary="No Opportunites Found" />
        <apex:commandButton value="Save Opportunities" action="{!saveopps}" rendered="{!opts.size !=0}"/>

    </apex:pageblock>
             
    <!--this block is used for displaying contact details -->
            
     <apex:pageblock rendered="{!flag3}">
         
     <apex:pageblocktable value="{!snts}" var="c">
        <apex:column >
            <apex:facet name="header">Contact Id</apex:facet>
            <apex:commandlink value="{!c}" Action="{!URLFOR($Action.contact.edit,c)}"/>
        </apex:column>
         <apex:column value="{!c.account.name}" />
        <apex:column >
             <apex:facet name="header">Contact Lastname</apex:facet>
            <apex:inputtext value="{!c.lastname}"/>
        </apex:column>
        <apex:column >
        <apex:facet name="header">Contact Department</apex:facet>
            <apex:inputtext value="{!c.Department}"/>
        </apex:column>
        </apex:pageblocktable>
        <apex:pageMessage rendered="{!conError}" severity="error" strength="1" summary="No Contacts Found" /> 
         <apex:commandButton value="Save Contacts" action="{!savecons}" rendered="{!snts.size !=0}"/>
    </apex:pageblock>
        </apex:outputPanel>
    </apex:form>
</apex:page>

 
Siva@51Siva@51
Hi Anudeep
=================================
Apex Class
================================
public class Acc_con_Opp_Details
{
    //list of collection of the wrapper class object
    public list<accountwrapper> actwrap           {set;get;}
    public list<accountwrapper> actwrap1           {set;get;}
    //list of collection of Account,contact and opportunity objects
    public list<Account>        accounts          {set;get;}
    public list<Account>        accounts1          {set;get;}
    public list<Account>        acts              {set;get;}
    public list<Account>        acts1              {set;get;}
    public list<opportunity>    opts              {set;get;}
    public list<opportunity>    sopts             {set;get;}
    public list<contact>        cnts              {set;get;} 
    public list<contact>        snts              {set;get;}
    public string               searchstring      {get;set;}//used in searching account records 
    public boolean oppbox                         {set;get;}//used as check box for opportunity 
    public boolean conbox                         {set;get;}//used as check box for contact
    public boolean flag1                          {set;get;}//used in account page block  
    public boolean flag2                          {set;get;}//used in contact page block 
    public boolean flag3                          {set;get;}//used in opportunity page block
    public boolean checkallflag                   {set;get;}//used for header check box
    public boolean nxt                            {get;set;}//this variable is used to enable or disable next and last buttons
    public Boolean oppError                       {set;get;}
    public Boolean conError                       {set;get;}
    public Boolean oppboxError                    {set;get;}
    public Boolean conboxError                    {set;get;}
    public Boolean accountsError                  {set;get;}
    public Boolean searchError                  {set;get;}
    public Boolean searchBox                      {set;get;}
    public Boolean checkIndex                     {set;get;}
    public list<String> AlphaList                 {get; set;}
    public String AlphaFilter                     {get; set;}
    private String Query;
    //this variables are used for pagination purpose
    private integer totalRecs = 0;//stores no.of total records   
    private integer index = 0;//used for tracking offset
    private integer blockSize =5;//for setting size of page
    private String sortDirection = 'ASC';
    private String sortExp = 'Name';
    public Map<String, String> mapAlpha{get; set;}
 
    //in this constructor we are setting values to boolean values
    public Acc_con_Opp_Details()
    {
    flag1=true;
    flag2=false;
    flag3=false;
    oppError=false;
    conError=false;
    checkallflag = false;
    accountsError = false;
    searchBox=false;
    searchError=false;
    totalRecs = [select count() from Account];//returns total no.of account records 
    getactwrap();//calling getactwrap method.
    AlphaList = new list<String> {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'Other', 'All'};
    if (apexpages.currentpage().getparameters().get('alpha') == null) {
        AlphaFilter = 'All';
    } else {
        AlphaFilter = apexpages.currentpage().getparameters().get('alpha');
    }
    }
    public String sortExpression
    {
      get
      {
         return sortExp;
      }
      set
      {
        //if the column is clicked on then switch between Ascending and Descending modes
        if (value == sortExp)
          sortDirection = (sortDirection == 'ASC')? 'DESC' : 'ASC';
        else
          sortDirection = 'ASC';
          sortExp = value;
      }
    }

    public String getSortDirection()
    {
       //if not column is selected 
       if (sortExpression == null || sortExpression == '')
           return 'ASC';
       else
          return sortDirection;
    }

    public void setSortDirection(String value)
    {  
        sortDirection = value;
    }
    //this method displays first five records
    public void beginning()
    {    
        flag2 = false;
        flag3 = false;
        oppbox=false;
        conbox=false;
        checkallflag=false;
        index = 0;
        if(searchBox == true) {
             search();   
        } else {
            getactwrap();
        }
    }
    //this method displays prevoius records
    public void previous()
    {    
        flag2 = false;
        flag3 = false;
        oppbox=false;
        conbox=false;
        checkallflag=false;
        index = index-blockSize;
        if(searchBox == true) {
             search();   
        } else {
            getactwrap();
        }
    }
    //this method displays next records
   public void next()
    {    
        flag2 = false;
        flag3 = false;
        oppbox=false;
        conbox=false;
        checkallflag=false;
        index = index+blockSize;
        if(searchBox == true) {
             search();   
        } else {
            getactwrap();
        }
    }
    //this method displays last remaining records
 public void end()
    {    
        flag2 = false;
        flag3 = false;
        oppbox=false;
        conbox=false;
        checkallflag=false;
        index = totalRecs - math.mod(totalRecs ,blockSize);
        if(searchBox == true) {
             search();   
        } else {
            getactwrap();
        }
    }  
    //this variable is used to enable or disable first and previous buttons
 public boolean prev{get
    {
        if(index == 0)
        return true;
        else
        return false;
    }  set;}
    
    //used to display opportunities and contacts w.r.t selected accounts
    public void  submit()
    {
        flag1=false;
        acts=new list<Account>();
        List<Boolean> acflagList = new List<Boolean>();
        for(accountwrapper aw:actwrap)
           {
            if(aw.acflag){
                acts.add(aw.acc);
                acflagList.add(aw.acflag);
           } 
        }
        if(acflagList.isEmpty()) {
           if(oppbox && actwrap.size() > 0)
               oppboxError=true;
           if(conbox && actwrap.size() > 0)
               conboxError=true;
           flag2=false;
           flag3=false;
           oppError=false;
           conError=false;
        } else {
            oppboxError=false;
            conboxError=false;
        }
        
        //if we select contact check box,then it displays contacts for selected accounts 
      if(conbox)
      {
              snts=[select id,lastName,Department,account.name from contact where accountid IN:acts];
              if(snts.size()>0)
              {
                  flag3=true;
                  conError=false;
              }
              else
              {
                  for(accountwrapper aw : actwrap) {
                      if(aw.acflag) {
                          flag3=true;
                          conError = true;
                      }
                          //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'contact records are not found for selected Accounts.'));
                    }
              }
         } else {
             flag3 = false;
         }
        //if we select opportunity check box,then it displays opportunities for selected accounts
      if(oppbox)
        {
              opts=[select id,name,stageName,leadsource,account.name from opportunity where accountId IN:acts];
              if(opts.size() >0)
              {
                  flag2=true;
                  oppError=false;
              }
              else       
              {    
                    for(accountwrapper aw : actwrap) {
                      if(aw.acflag) {
                          flag2=true;
                          oppError = true;
                      }
                          //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'opportunity records are not found for selected Accounts.'));
                    }
              }
        } else {
            flag2 = false;
        }
    }
    public void Index() {
        index=0;
        getactwrap();
    }
    public void search(){
        searchBox=true;
        String searchQuery =  ''; 
        string sortFullExp = sortExpression  + ' ' + sortDirection;
        searchQuery = 'SELECT Id, Name, phone ' + ' FROM Account ' + 'WHERE ' + 'Name' + ' LIKE \'' + searchstring + '%\'' + ' ORDER BY ' + sortFullExp + ' LIMIT : blockSize OFFSET : index ' ;
        System.debug('+++++++++++++++++'+searchQuery);
        accounts1 = Database.Query(searchQuery);
        actwrap1=new list<accountwrapper>();
        if(searchstring.isAlpha() && searchstring.length() >=3) {
            searchError=false;
            for(account a:accounts1)
            {
                actwrap1.add(new accountwrapper(a));
            }
            if(actwrap1.isEmpty()) {
                accountsError = true;
                nxt=true;
            } else {
                nxt=false;
                accountsError = false;
            }
        } else {
            searchError=true;
        }
        flag2=false;
        flag3=false;
        oppbox=false;
        conbox=false;
        checkallflag=false;
    }
   //it hides contacts and dispalys opportunitites on uncheck of contact check box
   //This method uses a simple SOQL query to return a List of Accounts
    public void getactwrap() {
        searchError=false;
        searchBox=false;
        String QueryIf = '';
        string sortFullExp = sortExpression  + ' ' + sortDirection;
        
        if (AlphaFilter == null || AlphaFilter.trim().length() == 0) {
            AlphaFilter = 'All';
        }
        
        Query = 'SELECT Id, Name, phone ' + ' FROM Account'; 
        
        if (AlphaFilter == 'Other') {
            QueryIf = QueryFor(QueryIf, '(' + 'Name' + ' < \'A\' OR ' + 
                                    'Name' + ' > \'Z\') AND (NOT ' + 
                                    'Name' + ' LIKE \'Z%\') ');
        } else if (AlphaFilter != 'All') {
            QueryIf = QueryFor(QueryIf, '(' + 'Name' + ' LIKE \'' + String.escapeSingleQuotes(AlphaFilter) + '%\')' );
        }
        
        Query += QueryIf;
        Query += ' ORDER BY ' + sortFullExp + ' LIMIT : blockSize OFFSET : index';
        accounts = Database.Query(Query);
        actwrap=new list<accountwrapper>();
       // As each Account is processed we create a new accountwrapper object and add it to the wrapper class(accountwrapper) list.
        for(account a:accounts)
        {
            actwrap.add(new accountwrapper(a));
        }
        if(actwrap.isEmpty()) {
            accountsError = true;
            nxt=true;
        } else {
            nxt=false;
            accountsError = false;
        }
        flag2=false;
        flag3=false;
        oppbox=false;
        conbox=false;
        checkallflag=false;
    }
    public String QueryFor(String Q, String C) {
        if (Q == '') {
            return ' WHERE ' + C;
        } else {
            return Q + ' AND ' + C;
        }
    }
      
    public void Hideandshowopp()
    {
     
        if(oppbox)
          {     
              submit();
          } else {
              flag2 = false;
          }
         
    }
   //  it hides opportunities and dispalys contacts on uncheck of opportunities check box 
     public void HideandshowCon()
    {
        if(conbox)
         {    
              submit();
          } else {
              flag3 = false;
          }
         
    }
   
    public void Hideandshowoppcon() {
        Hideandshowopp();
        Hideandshowcon();
    }
    
    
    // this method  uses dml operation to edit the existing opportunities values or to insert new oppt values
    public void saveopps()
    {
        list<opportunity> opps=new list<opportunity>();
        opps.addAll(opts);
        upsert opps;
    }
    //his method  uses dml operation to edit the existing contact values or to insert new contact values
    public void savecons()
    {
       cnts = new list<contact>();
        cnts.addall(snts);
        upsert cnts;
    }
 //This is wrapper class which is collection of other class instances
  //here  wrapper class contains both the standard salesforce object Account and a Boolean value acflag   
 public class accountwrapper{
        public account acc{set;get;}
        public boolean acflag{set;get;}
             //In this contructor When we create a new accountwrapper object we pass a Account that is set to the acc property.
             // We also set the boolean value to false
        public accountwrapper(account a){
            acc=a;
            acflag=false;
        }
        
    }

}
=================================
Siva@51Siva@51
VF Page
========================================
<apex:page controller="Acc_con_Opp_Details" showHeader="false" docType="html-5.0">
    <style type="text/css">
    a.alpha-select {
       font-weight: bold;
       text-decoration: none;
       background-color: #C6E1FF;
       color: #000000 !important;
    }
    </style>
    <script>
    function checkallflag(allCheckboxes) {
    
        var container = allCheckboxes;
        while (container.tagName != "TABLE") {
            container = container.parentNode;
        }
    
        var inputs = container.getElementsByTagName("input");
        var checked = allCheckboxes.checked;
        for (var i = 0; i < inputs.length; i++) { 
            var input = inputs.item(i);
            if (input.type == "checkbox") {
                if (input != allCheckboxes) {
                    input.checked = checked;
                }
            }
        }
        CallSubmitMethod();
    }
    </script>
    <apex:form >
    <apex:actionFunction name="CallSubmitMethod" action="{!submit}"/>
    <!--This block dispalying account record details-->
    <apex:outputPanel id="par">
        
           
    <apex:pageblock rendered="true">
         &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; enter:
         <apex:inputText value="{!searchstring}"/>
         &nbsp;&nbsp;&nbsp;<apex:commandButton value="Search records" action="{!search}"/>
        <br/><br/> 
        <apex:repeat value="{!AlphaList}" var="a">
          <apex:commandLink value="{!a}" action="{!Index}" styleClass="alpha-link{!if(AlphaFilter=a,' alpha-select','')}">
             <apex:param name="AlphaFilter" value="{!a}" assignTo="{!AlphaFilter}"/>
          </apex:commandLink>
          <apex:outputText >  |  </apex:outputText>
       </apex:repeat>
    <apex:pageMessages ></apex:pageMessages>
    <apex:pageMessage rendered="{!searchError}" severity="error" strength="1" summary="please enter minimum 3 letters to search" />
    <apex:pageblocktable value="{!if(searchBox == true, actwrap1, actwrap)}" var="a">
        <apex:column >
            <apex:facet name="header">
                <apex:inputCheckbox onclick="checkallflag(this)" value="{!checkallflag}"/>
            </apex:facet>
            <!--<apex:facet name="header">Select</apex:facet>-->
             <apex:inputCheckbox value="{!a.acflag}">
                 <apex:actionSupport event="onchange" action="{!Hideandshowoppcon}" reRender="par"/>
             </apex:inputCheckbox>
        </apex:column>
        <!-- displays id,name and phone number for accounts-->
        <apex:column value="{!a.acc.id}" width="30%"/>
        <apex:column width="50%">
         <apex:facet name="header">   
           <apex:commandLink action="{!getactwrap}" value="Name{!IF(sortExpression=='name',IF(sortDirection='ASC','▼','▲'),'▼')}">
             <apex:param value="name" name="column" assignTo="{!sortExpression}"></apex:param>
           </apex:commandLink>
         </apex:facet>
         <apex:outputLabel >{!a.acc.Name}</apex:outputLabel>
       </apex:column>
        <apex:column value="{!a.acc.phone}" width="50%"/>
         </apex:pageblocktable>
        <!-- this buttons are used to paginate account records-->
       <apex:pageMessage rendered="{!accountsError}" severity="error" strength="1" summary="No Accounts Found" />
        <apex:pageblockButtons location="top">
            <!--displays first five records-->
            <apex:commandButton value="first"  action="{!beginning}" disabled="{!prev}" style="height:22px;width:57px;"/>
            <!--displays previous records-->
            <apex:commandButton value="previous"  action="{!previous}" disabled="{!prev}" style="height:22px;width:57px;"/>
             <!--displays previous  next records-->
            <apex:commandButton value="next"  action="{!next}" disabled="{!nxt}" style="height:22px;width:57px;"/>
            <!-- displays last records-->
            <apex:commandButton value="last"  action="{!end}" disabled="{!nxt}" style="height:22px;width:57px;"/>                                    
        </apex:pageblockButtons>
         <!-- check boxs for opportunities and contacts-->
       
     <center>  <apex:inputCheckbox value="{!oppbox}">
     <apex:actionSupport event="onchange" action="{!Hideandshowopp}"/>
     </apex:inputCheckbox>Opportunities&nbsp;&nbsp;&nbsp;
         <apex:inputCheckbox value="{!conbox}">
         <apex:actionSupport event="onchange" action="{!HideandshowCon}"/>
         </apex:inputCheckbox>Contacts&nbsp;&nbsp;&nbsp;
       <!-- <apex:commandButton value="submit" action="{!submit}"/>-->
       </center>
       <apex:pageMessage rendered="{!oppboxError}" severity="error" strength="1" summary="Choose atleast one account record to display opportunities" /> 
       <apex:pageMessage rendered="{!conboxError}" severity="error" strength="1" summary="Choose atleast one account record to display contacts" /> 
    </apex:pageblock>
    <!--this block displays opportunity details-->
    <apex:pageblock rendered="{!flag2}">
       
   <apex:pageblocktable value="{!opts}" var="o">
        <apex:column >
             <apex:facet name="header">Opportunity Id</apex:facet>
            <apex:commandlink value="{!o.id}" Action="{!URLFOR($Action.opportunity.edit,o.Id)}"/>
        </apex:column>
        <apex:column value="{!o.account.name}" />
        <apex:column >
            <apex:facet name="header">Opportunity Name</apex:facet>
       <apex:inputtext value="{!o.name}" />
            </apex:column>
        <apex:column >
           <apex:facet name="header">Opportunity Stage</apex:facet> 
       <apex:inputtext value="{!o.stagename}"/>
        </apex:column>
       <apex:column >
         <apex:facet name="header">Opportunity Leadsource</apex:facet> 
        </apex:column>
        </apex:pageblocktable>
        <apex:pageMessage rendered="{!oppError}" severity="error" strength="1" summary="No Opportunites Found" />
        <apex:commandButton value="Save Opportunities" action="{!saveopps}"/>
    </apex:pageblock>
             
    <!--this block is used for displaying contact details -->
            
     <apex:pageblock rendered="{!flag3}">
         
     <apex:pageblocktable value="{!snts}" var="c">
        <apex:column >
            <apex:facet name="header">Contact Id</apex:facet>
            <apex:commandlink value="{!c}" Action="{!URLFOR($Action.contact.edit,c)}"/>
        </apex:column>
         <apex:column value="{!c.account.name}" />
        <apex:column >
             <apex:facet name="header">Contact Lastname</apex:facet>
            <apex:inputtext value="{!c.lastname}"/>
        </apex:column>
        <apex:column >
        <apex:facet name="header">Contact Department</apex:facet>
            <apex:inputtext value="{!c.Department}"/>
        </apex:column>
        </apex:pageblocktable>
        <apex:pageMessage rendered="{!conError}" severity="error" strength="1" summary="No Contacts Found" /> 
         <apex:commandButton value="Save Contacts" action="{!savecons}" />
    </apex:pageblock>
        </apex:outputPanel>
    </apex:form>
</apex:page>
================================================
anu deep 6anu deep 6
Hi siva,

Kindly please help me to achieve following enhancements
1.)If user enter some words with spaces in the text box and on click of search records, it should show the accounts whose names matches those words.
2)Display opportunites/contacts checkboxes only if selected accounts have opportunities or contact records.

NOTE:-PLEASE FIND APEX CONTROLLER AND VF PAGES IN BELOW POSTS.
 
anu deep 6anu deep 6
HI siva, *Kindly please help me to achieve following enhancements1.)If user enter some words with spaces in the text box and on click of search records, it should show the accounts whose names matches those words.2)Display opportunites/contacts checkboxes only if selected accounts have opportunities or contact records.* *Apex controller============public class Acc_con_Opp_Details{ //list of collection of the wrapper class object public list actwrap {set;get;} public list actwrap1 {set;get;} //list of collection of Account,contact and opportunity objects public list accounts {set;get;} public list accounts1 {set;get;} public list acts {set;get;} public list acts1 {set;get;} public list opts {set;get;} public list sopts {set;get;} public list cnts {set;get;} public list snts {set;get;} public string searchstring {get;set;}//used in searching account records public boolean oppbox {set;get;}//used as check box for opportunity public boolean conbox {set;get;}//used as check box for contact public boolean oppCheckBox {set;get;}//used to dispaly/disable opportunity check box public boolean conCheckBox {set;get;}//used to display/disable contact check box public boolean flag1 {set;get;}//used in account page block public boolean flag2 {set;get;}//used in contact page block public boolean flag3 {set;get;}//used in opportunity page block public boolean checkallflag {set;get;}//used for header check box public Boolean oppError {set;get;}//used to dispaly opportunities error public Boolean conError {set;get;}//used to dispaly contacts error public Boolean oppboxError {set;get;}//used to dispaly opportunities error public Boolean conboxError {set;get;}//used to display contacts error public Boolean accountsError {set;get;}//used to dispaly accounts error public Boolean opp_con_error {set;get;}//used to dispaly both contacts and account error public Boolean searchError {set;get;}//used to dispaly error below search box public Boolean searchBox {set;get;}//used for text box in searching account records public Boolean checkIndex {set;get;}// public list AlphaList {get;set;}//used to collect the list of alphabets public String AlphaFilter {get;set;}// private String Query;// //this variables are used for pagination purpose private integer totalRecs = 0;//stores no.of total records private integer index = 0;//used for tracking offset private integer blockSize =5;//for setting size of page private String sortDirection = 'ASC';//default ascending order private String sortExp ='Name'; //in this constructor we are setting values to boolean values public Acc_con_Opp_Details() { //initially assigning false value to all boolean variables flag2=false; flag3=false; oppError=false; conError=false; checkallflag = false; accountsError = false; oppboxError=false; conboxError=false; searchBox=false; searchError=false; oppCheckBox=true; conCheckBox=true; totalRecs = [select count() from Account];//returns total no.of account records getactwrap();//calling getactwrap method. //collecting list of all alphabets AlphaList = new list {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'Other', 'All'}; //getting the values from vf pages if(apexpages.currentpage().getparameters().get('alpha') == null) { AlphaFilter = 'All'; } else { AlphaFilter = apexpages.currentpage().getparameters().get('alpha'); } } //used for sorting name column public String sortExpression { get { return sortExp; } set { //if the column is clicked on then switch between Ascending and Descending modes if (value == sortExp) sortDirection = (sortDirection == 'ASC')? 'DESC' : 'ASC'; else sortDirection = 'ASC'; sortExp = value; } } //used for sorting name column public String getSortDirection() { //if not column is selected if (sortExpression == null || sortExpression == '') return 'ASC'; else return sortDirection; } public void setSortDirection(String value) { sortDirection = value; } //this method displays first five records public void beginning() { flag2 = false;//hides contact records flag3 = false;//hides opportunity records oppbox=false;//disables the opportunity check box conbox=false;//disables the contact check box checkallflag=false;//disables the account header check box oppboxError=false;//disables the opportunity error conboxError=false;//disables the contact error index = 0;//initially index would be zero oppCheckBox=true; conCheckBox=true; if(searchBox == true) { search(); //searchs account records based on enrty criteria } else { getactwrap();//display all account records } } //this method displays prevoius records public void previous() { flag2 = false; flag3 = false; oppbox= false; conbox= false; oppboxError=false; conboxError=false; checkallflag=false; oppCheckBox=true; conCheckBox=true; index = index-blockSize; if(searchBox == true) { search();//searchs account records based on enrty criteria } else { getactwrap();//display all account records } } //this method displays next records public void next() { oppCheckBox=true; conCheckBox=true; flag2 = false; flag3 = false; oppbox= false; conbox= false; oppboxError=false; conboxError=false; checkallflag=false; index = index+blockSize; if(searchBox == true) { search();//searchs account records based on entry criteria } else { getactwrap();//display all account records } } //this method displays last remaining records public void end() { oppCheckBox=true; conCheckBox=true; flag2 = false; flag3 = false; oppbox=false; conbox=false; oppboxError=false; conboxError=false; checkallflag=false; index = totalRecs - math.mod(totalRecs ,blockSize);//used to dispaly remainig last records if(searchBox == true) { search();//searchs account records based on enrty criteria } else { getactwrap();//display all account records } } //this variable is used to enable or disable first and previous buttons public boolean prev{get { if(index == 0) return true; else return false; } set;} public boolean nxt{get { if((index + blockSize) > totalRecs) return true; else return false; } set;} //used to display opportunities and contacts w.r.t selected accounts public void submit() { acts=new list(); List acflagList = new List();//used for collection of list of check boxs for(accountwrapper aw:actwrap) { if(aw.acflag) { acts.add(aw.acc); acflagList.add(aw.acflag);//used to collect all checked account records } } if(acflagList.isEmpty()) { if(oppbox && actwrap.size()>0)// oppboxError=true; if(conbox && actwrap.size()>0)// conboxError=true;// if(conbox && oppbox && actwrap.size()>0) { oppboxError=false; conboxError=false; opp_con_error=true; } flag2=false; flag3=false; oppError=false; conError=false; } else { oppboxError=false; conboxError=false; opp_con_error=false; } //if we select contact check box,then it displays contacts for selected accounts if(conbox) { snts=[select id,lastName,Department,account.name from contact where accountid IN:acts];//simple soql which returns contacts if(snts.size()>0) { flag3=true; conError=false; } else { for(accountwrapper aw : actwrap) { if(aw.acflag) { flag3=true; conError = true; } //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'contact records are not found for selected Accounts.')); } } } else { flag3 = false; } //if we select opportunity check box,then it displays opportunities for selected accounts if(oppbox) { opts=[select id,name,stageName,leadsource,account.name from opportunity where accountId IN:acts]; if(opts.size() >0) { flag2=true; oppError=false; } else { for(accountwrapper aw : actwrap) { if(aw.acflag) { flag2=true; oppError = true; } //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'opportunity records are not found for selected Accounts.')); } } } else { flag2 = false; } for(accountwrapper aw:actwrap) { if(aw.acflag) { opts=[select id,name,stageName,leadsource,account.name from opportunity where accountId IN:acts]; if(opts.size() from contact where accountid IN:acts]; if(snts.size()(); if(searchstring.length()>=3) { searchError=false; for(account a:accounts1) { actwrap1.add(new accountwrapper(a)); } if(actwrap1.isEmpty()) { accountsError = true; nxt=true; } else { nxt=false; accountsError = false; } } else { if(searchString.length()==null||searchString.length()==0) { getactwrap(); } else searchError=true; } flag2=false; flag3=false; oppbox=false; conbox=false; checkallflag=false; } //it hides contacts and dispalys opportunitites on uncheck of contact check box //This method uses a simple SOQL query to return a List of Accounts public void getactwrap() { searchError=false; searchBox=false; String QueryIf = ''; string sortFullExp = sortExpression + ' ' + sortDirection; if (AlphaFilter == null || AlphaFilter.trim().length() == 0) { AlphaFilter = 'All'; } Query = 'SELECT Id, Name, phone ' + ' FROM Account'; if (AlphaFilter == 'Other') { QueryIf = QueryFor(QueryIf, '(' + 'Name' + ' < \'A\' OR ' + 'Name' + ' > \'Z\') AND (NOT ' + 'Name' + ' LIKE \'Z%\') '); } else if (AlphaFilter != 'All') { QueryIf = QueryFor(QueryIf, '(' + 'Name' + ' LIKE \'' + String.escapeSingleQuotes(AlphaFilter) + '%\')' ); } Query += QueryIf; Query += ' ORDER BY ' + sortFullExp + ' LIMIT : blockSize OFFSET : index'; accounts = Database.Query(Query); actwrap=new list(); // As each Account is processed we create a new accountwrapper object and add it to the wrapper class(accountwrapper) list. for(account a:accounts) { actwrap.add(new accountwrapper(a)); } if(actwrap.isEmpty()) { accountsError = true; nxt=true; } else { nxt=false; accountsError = false; } flag2=false; flag3=false; oppbox=false; conbox=false; checkallflag=false; } public String QueryFor(String Q, String C) { if (Q == '') { return ' WHERE ' + C; } else { return Q + ' AND ' + C; } } public void Hideandshowopp() { if(oppbox) { submit(); } else{ flag2 = false; oppBoxError=false; opp_con_error=false; } } // it hides opportunities and dispalys contacts on uncheck of opportunities check box public void HideandshowCon() { if(conbox) { submit(); } else { flag3 = false; conBoxError=false; opp_con_error=false; } } public void Hideandshowoppcon() { Hideandshowopp(); Hideandshowcon(); } // this method uses dml operation to edit the existing opportunities values or to insert new oppt values public void saveopps() { list opps=new list(); opps.addAll(opts); upsert opps; } //his method uses dml operation to edit the existing contact values or to insert new contact values public void savecons() { cnts = new list(); cnts.addall(snts); upsert cnts; } //This is wrapper class which is collection of other class instances //here wrapper class contains both the standard salesforce object Account and a Boolean value acflag public class accountwrapper{ public account acc{set;get;} public boolean acflag{set;get;} //In this contructor When we create a new accountwrapper object we pass a Account that is set to the acc property. // We also set the boolean value to false public accountwrapper(account a){ acc=a; acflag=false; } }}* *vf page======= a.alpha-select { font-weight: bold; text-decoration: none; background-color: #C6E1FF; color: #000000 !important; }           enter:

| {!a.acc.Name } Opportunities    Contacts    Opportunity Id Opportunity Name Opportunity Stage Opportunity Leadsource Contact Id Contact Lastname Contact Department *
anu deep 6anu deep 6
Hi siva

I am waititng for your reply,Kindly, please help me.Thanks for great support.
aishwarya tyagi 4aishwarya tyagi 4
As a adim I m Unable to login into my account. An error is coming while login i.e Your access is blocked due to security purpose please contact adminstrator. My trailhead account also linked with my dev org.
Syed Subhan 9Syed Subhan 9
Hi Siva,
Need your help on some requirment.
I am querying some records from opportunity and placing a check box next to each record displayed.
I am able to download all the records by keeping download button.
But, my requirement is to download only the records which I check in check box next to each records. i.e if i select/check 3 records i should be able to download only those 3 checked records not all the queried records.....
Please help on this.
Syed Subhan 9Syed Subhan 9
hi Siva,
Need your help on some requirment.
I am querying some records from opportunity and placing a check box next to each record displayed.
I am able to download all the records by keeping download button.
But, my requirement is to download only the records which I check in check box next to each records. i.e if i select/check 3 records i should be able to download only those 3 checked records not all the queried records.....
​Please help on this.User-added image
Buck DukhBuck Dukh
I am facing an error while creating title boxing gloves sizing (https://keeperspro.com/best-boxing-gloves/) in my website. how to fix it?