******************************************************\t   ************ControllerPage*********************************   public class TestPage {         public Account acc {get;set;}           public List contactlist{get;set;}          public List con{get;set;}                                    public TestPage()          {              acc=new Account();              contactlist= new List();              }      public PageReference getContacts() {         con= [select id, firstname, AssistantName,Birthdate,Phone from Contact where Accountid =: acc.parentid];         system.debug('#########'+con);           contactlist= new List();         for(Contact c: con)         {             contactlist.add(new Contactwrapper(c,false));        }        system.debug('#########'+contactlist);              return null;              }       public PageReference getSelected()      {        //  contactlist.clear();          for(Contactwrapper awp:contactlist)          if(awp.selected == true)          {         // contactlist.add(accwrapper.acc);           system.debug('********'+awp.cw.firstname);                     }          return null;      }            public pageReference getDelete(){      List dList = new List();       for(Contactwrapper wrap: contactlist){          if(wrap.selected == true)          {          dList.add(wrap.cw);          }          }           if(dList !=null && dList.size() >0){           delete dList;           }          return null;      }            public void getCancel(){            }             public PageReference AddRow() {      Contact conObj = new Contact();      conlist.add(new Contactwrapper(conObj,false));      return null;      }      public pageReference SaveRecord(){       List ctList = new List();           for(Contactwrapper wrap: contactlist){          if(wrap.selected == true)          {          ctList.add(wrap.cw);          }          }           if(ctList!=null && ctList.size() >0){           update ctList;           }          return null;      }            public class Contactwrapper{          public Contact cw{get; set;}          public Boolean selected{get; set;}                    public Contactwrapper(Contact c,boolean b){              cw = c;              selected = b;              // system.debug('********'+acc);          }      }   }", "upvoteCount": 0, "url": "https://trailhead.salesforce.com/trailblazer-community/feed/0D54S00000A7kf8SAB", "datePublished": "2013-08-20T07:27:18.000Z", "author": { "@type": "Person", "name": "Doga R", "url": "https://trailblazers.salesforce.com/profileView?u=00530000009ZGnQAAW", "affiliation": { "@type": "Organization", "name": "--" } } } ] } } Skip to main content
public class TestPage {

 

       public Account acc {get;set;}

 

     

 

public List conlist{get;set;}

 

        public List con{get;set;}

 

      

 

      //  Public Contact inList{get;set;}

 

        // Public List l{get;set;}

 

         // List conlist;

 

       

 

        public TestPage()

 

        {

 

            acc=new Account();

 

            conList= new List();    

 

        }

 

    public PageReference getContacts() {

 

       con= [select id, firstname, AssistantName,Birthdate,Phone from Contact where Accountid =: acc.parentid];

 

       system.debug('#########'+con);

 

         conlist = new List();

 

       for(Contact c: con)

 

       {

 

            conlist.add(new Contactwrapper(c,false));

 

      }

 

      system.debug('#########'+conlist);

 

            return null;

 

      

 

    }

 

     public PageReference getSelected()

 

    {

 

      //  conlist.clear();

 

        for(Contactwrapper awp: conlist)

 

        if(awp.selected == true)

 

        {

 

       // conlist.add(accwrapper.acc);

 

         system.debug('********'+awp.cw.firstname);

 

        

 

         }

 

        return null;

 

    }

 

   

 

    public pageReference getDelete(){

 

    List dList = new List();

 

     for(Contactwrapper wrap: conlist){

 

        if(wrap.selected == true)

 

        {

 

        dList.add(wrap.cw);

 

        }

 

        }

 

         if(dList !=null && dList.size() >0){

 

         delete dList;

 

         }

 

        return null;

 

    }

 

   

 

    public void getCancel(){

 

   

 

    }

 

   

 

     public PageReference AddRow() {

 

    Contact conObj = new Contact();

 

    conlist.add(new Contactwrapper(conObj,false));

 

    return null;

 

    }

 

    public pageReference SaveRecord(){

 

     List ctList = new List();

 

         for(Contactwrapper wrap: conlist){

 

        if(wrap.selected == true)

 

        {

 

        ctList.add(wrap.cw);

 

        }

 

        }

 

         if(ctList!=null && ctList.size() >0){

 

         update ctList;

 

         }

 

        return null;

 

    }

 

   

 

    public class Contactwrapper{

 

        public Contact cw{get; set;}

 

        public Boolean selected{get; set;}

 

       

 

        public Contactwrapper(Contact c,boolean b){

 

            cw = c;

 

            selected = b;

 

            // system.debug('********'+acc);

 

        }

 

    }

 

}
4 answers
  1. Aug 20, 2013, 7:27 AM
    No i am getting below error

     

    "TestPage Compile Error: Invalid type: Contactwrapper at line 18 column 33 "

     

     

    Below is the complete code which i have taken from one site -

     

    ***************VF Page*****************************************

     

    <apex:page controller="TestPage" showHeader="True" sidebar="False" > <script> function savemsg() {alert('Record Saved!')} </script>

     

    <apex:form >

     

    <apex:pageBlock >

     

    <apex:pageblockSection >

     

    <apex:inputField value="{!acc.parentid}" label="Select Contact"/>

     

    </apex:pageblockSection>

     

    <apex:pageblockButtons location="Bottom">

     

    <apex:commandButton value="Show Contacts" action="{!getContacts}" reRender="Table"/>

     

    </apex:pageblockButtons>

     

    </apex:pageBlock>

     

    <apex:pageBlock id="table" title="Display Contacts">

     

     <apex:pageBlockSection >

     

     <apex:pageBlockTable value="{!contactlist}" var="c">

     

     <apex:column headerValue="Select" >

     

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

     

       <apex:actionSupport event="onclick" action="{!GetSelected}" rerender="Selected_PBS"/>

     

       </apex:inputCheckbox>

     

     </apex:column>

     

     <apex:column >

     

     <apex:inputField value="{!c.cw.firstname}"/>

     

      </apex:column>

     

     <apex:column >

     

     <apex:inputfield value="{!c.cw.AssistantName}" />

     

     </apex:column>

     

     </apex:pageBlockTable>

     

     </apex:pageBlockSection>

     

     </apex:pageBlock>

     

    </apex:form>

     

    </apex:page>

     

    ******************************************************

     

    ************ControllerPage*********************************

     

    public class TestPage {

     

          public Account acc {get;set;}

     

         

     

    public List<contact> contactlist{get;set;}

     

           public List<contact> con{get;set;}

     

         

     

         

     

           

     

           public TestPage()

     

           {

     

               acc=new Account();

     

               contactlist= new List();    

     

           }

     

       public PageReference getContacts() {

     

          con= [select id, firstname, AssistantName,Birthdate,Phone from Contact where Accountid =: acc.parentid];

     

          system.debug('#########'+con);

     

            contactlist= new List();

     

          for(Contact c: con)

     

          {

     

              contactlist.add(new Contactwrapper(c,false));

     

         }

     

         system.debug('#########'+contactlist);

     

               return null;

     

         

     

       }

     

        public PageReference getSelected()

     

       {

     

         //  contactlist.clear();

     

           for(Contactwrapper awp:contactlist)

     

           if(awp.selected == true)

     

           {

     

          // contactlist.add(accwrapper.acc);

     

            system.debug('********'+awp.cw.firstname);

     

           

     

            }

     

           return null;

     

       }

     

       

     

       public pageReference getDelete(){

     

       List dList = new List();

     

        for(Contactwrapper wrap: contactlist){

     

           if(wrap.selected == true)

     

           {

     

           dList.add(wrap.cw);

     

           }

     

           }

     

            if(dList !=null && dList.size() >0){

     

            delete dList;

     

            }

     

           return null;

     

       }

     

       

     

       public void getCancel(){

     

       

     

       }

     

       

     

        public PageReference AddRow() {

     

       Contact conObj = new Contact();

     

       conlist.add(new Contactwrapper(conObj,false));

     

       return null;

     

       }

     

       public pageReference SaveRecord(){

     

        List ctList = new List();

     

            for(Contactwrapper wrap: contactlist){

     

           if(wrap.selected == true)

     

           {

     

           ctList.add(wrap.cw);

     

           }

     

           }

     

            if(ctList!=null && ctList.size() >0){

     

            update ctList;

     

            }

     

           return null;

     

       }

     

       

     

       public class Contactwrapper{

     

           public Contact cw{get; set;}

     

           public Boolean selected{get; set;}

     

           

     

           public Contactwrapper(Contact c,boolean b){

     

               cw = c;

     

               selected = b;

     

               // system.debug('********'+acc);

     

           }

     

       }

     

    }
0/9000