+ Start a Discussion
sarath garimellasarath garimella 

A controller extension for a custom controller?

Hi,
I would like to know how we can create a controller extension for a custom controller.

My custom controller:

public class account_details{

public list<Account> accnt_list{get;set;}

public account_details(){
accnt_list= new list<Account>();
accnt_list=[select id,Name,BillingStreet,BillingCity,BillingState,BillingPostalCode,BillingCountry,ShippingStreet,ShippingCity,ShippingState,ShippingPostalCode,ShippingCountry FROM Account order by Name];
}
public pagereference edit_row(){
string str=apexpages.currentpage().getparameters().get('edit_id');
system.debug('------->'+str);
pagereference pg=new pagereference('/'+str+'/e');
return pg;
}
MY PAGE:

<apex:page controller="account_details">
  <apex:sectionHeader title="Account details"/>
  <apex:form >
   <apex:pageBlock >
   <apex:pageBlockSection >
   <apex:pageBlockTable value="{!accnt_list}" var="test_var">
   <apex:column headerValue="Action">
   <apex:commandLink value="EDIT" action="{!edit_row}">
   <apex:param name="edit_id" value="{!test_var.id}"/>
   </apex:commandLink>
   </apex:column>
   <apex:column headerValue="Account Name" value="{!test_var.Name}"/>
   <apex:column headerValue="Billing Street" value="{!test_var.BillingStreet}"/>
   <apex:column headerValue="Billing City" value="{!test_var.BillingCity}"/>
   <apex:column headerValue="Billing State" value="{!test_var.BillingState}"/>
   <apex:column headerValue="Billing Zip Code" value="{!test_var.BillingPostalCode}"/>    
   <apex:column headerValue="Billing Country" value="{!test_var.BillingCountry}"/>      
   <apex:column headerValue="Shipping Street" value="{!test_var.ShippingStreet}"/>
   <apex:column headerValue="Shipping City" value="{!test_var.ShippingCity}"/>
   <apex:column headerValue="Shipping State" value="{!test_var.ShippingState}"/>
   <apex:column headerValue="Shipping Zip Code" value="{!test_var.ShippingPostalCode}"/>    
   <apex:column headerValue="Shipping Country" value="{!test_var.ShippingCountry}"/>        
   </apex:pageBlockTable>
  
   </apex:pageBlockSection>
    </apex:pageBlock>

---------------------------------
So now I would like to create an extension so that I would like to use STR value(the id of account) and use it in another page. I tried online but all the codes I see are for a standard controller extension.

Thanks in advance
BalajiRanganathanBalajiRanganathan
public class myControllerExtension {
    account_details customController = null;

    public myControllerExtension(account_details customController) {
      this.customController = customController;
    }
}

As per documentation

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.
Karna_ShivaKarna_Shiva
I think he just asking how to create controller extension?

A controller extension is any Apex class containing a constructor and when we use apex class on Extensions that is called controller extension
<apex:page controller="classname" extensions="extenClass"/>

we can create extension class instead of touching controller class or old class and can use when you want extend standard controller functionality.
 
TanDTanD

@balaji,
I am trying to write Extension for custom controller, but getting the error "duplicate variable customcontroller attempt to recreate variable with the type customcontroller" 

any idea?