function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
manjunath vivekmanjunath vivek 

How does a constructor work in the following code.

apex:page standardController="Member__c" extensions="Search" >

  <style type = "text/css">
    .Bld { font-weight:bold;}
  </style>
 
  <apex:form >
 
    <apex:pageblock title="Members" >
      <table align = "center" width = "100%" cellspacing = "5">
        <tr>
          <td class = "Bld">Member Name:</td>
          <td><apex:inputText value="{!memName}" /></td>         
        </tr>
        <tr>
          <td align = "center" class = "Bld" colspan = "2"><apex:commandButton value="Find" action="{!find}"/></td>
        </tr>       
      </table>
      
    </apex:pageblock>
       
    <apex:pageBlock title="Search Result">
      <apex:pageblockTable value="{!memList}" var="a">
        <apex:column >
          <apex:outputlink value="https://na12.salesforce.com/{!a.id}">{!a.Name}</apex:outputlink>
        </apex:column>
        <apex:column value="{!a.id}"/>
      </apex:pageBlockTable>    
    </apex:pageBlock>   
     
  </apex:form>
</apex:page>

Apex:

public class Search
{
 
  public String memName {get; set;}
 
  public List<Member__c>  memList {get; set;}
 
  public Search(ApexPages.StandardController controller)
  {
  }
 
  public void find()
  {
    String sql = 'SELECT Name,id FROM Member__c WHERE Name LIKE \'%'+memName+'%\' LIMIT 20';
    memList = Database.query(sql);
  } 
}


Can some one explain, How does this line works in the above code .
public Search(ApexPages.StandardController controller)
  {
  }
Mohith Kumar ShrivastavaMohith Kumar Shrivastava
A controller extension is any Apex class containing a constructor that takes a single argument of type ApexPages.StandardController or CustomControllerName, where CustomControllerName is the name of a custom controller you want to extend.

http://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_extension.htm

Refer above link to deep drive .So In short an extension requires you to specify constructor and constructor is parameterized .In your case constructor has an object instance of Member__c .In fact for your case you dont need extension at all .Ideal will be custom controller
AshlekhAshlekh
Hi,

Hope below links will help you to understand the lifecycle of get and put request of page with extension.s

https://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_get_request.htm

https://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_lifecycle_example.htm
Ramakrishnan AyyanarRamakrishnan Ayyanar
you must know Order of Execution for Visualforce.

i share that link please read it that.

https://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_get_request.htm
manjunath vivekmanjunath vivek
Hi all thanks for your answers, your information was so helpfu.