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
Prallavi DuaPrallavi Dua 

Extension Constructor

Hi,

In the below code, can any one explain the extension constructor, i.e.
 Contact newCon;
public exampleClass1(ApexPages.StandardController con) {
          this.newCon = (Contact)con.getRecord();
}
code:
public with sharing class exampleClass1 {
  Contact newCon;
  public exampleClass1(ApexPages.StandardController con) {
          this.newCon = (Contact)con.getRecord();
      }
    public pagereference save(){
      Account a = New Account(Name = newCon.FirstName + ' ' + newCon.LastName);
      Insert a;
      newCon.AccountID = a.id;
      insert newCon;

      Pagereference pr = New PageReference('/' + a.id);
      return pr;
   }
}

<apex:page standardController="Account" recordSetVar="count" >
  <apex:form >
      <apex:pageBlock >
          <apex:pageBlockTable value="{!count}" var="ac">
              <apex:column value="{!ac.Name}"/>
              <apex:column value="{!ac.Industry}"/>
          </apex:pageBlockTable>
              <apex:pageBlock >
                  <apex:commandButton value="Save" action="{!save}" />
                      <apex:pageblocksection >
                          Enter Name: <apex:inputText value="{!Account.Name}"/>
                      </apex:pageblocksection>
              </apex:pageBlock>
      </apex:pageBlock>
  </apex:form>
</apex:page>