Netmaster
Netmaster

Reputation: 287

Error : Unknown constructor

I have created a custom object "Assure__c" and a custom apex class "insEnfant" like this :

<apex:page standardController="Assure__c" extensions="insEnfant"  standardStylesheets="true">
    <apex:sectionHeader title="Ajouter un assuré"
        subtitle="{!$User.FirstName}" help="/help/doc/user_ed.jsp?loc=help"></apex:sectionHeader>
    <apex:form >
        <apex:pageBlock title="Nouveau assuré" id="thePageBlock" mode="edit">
            <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="Enregistrer"></apex:commandButton>
                <apex:commandButton action="{!cancel}" value="   Annuler   "></apex:commandButton>
            </apex:pageBlockButtons>

            <apex:pageBlockSection title="Liste des enfants" columns="1"
                rendered="{!IF(Assure__c.Nombre_enfants__c > 0, true, false)}">


            <apex:pageBlockTable value="{!accts}" var="a" id="table">
                <apex:facet name="footer">
                    <apex:commandLink value="Ajouter" action="{!addRow}" rerender="table,error"/>
                </apex:facet>

                <apex:column headerValue="Nom">
                    <apex:inputHidden value="{!Assure__c.Name}" id="theHiddenInput"/>
                </apex:column>
                <apex:column headerValue="Nom">
                    <apex:inputField value="{!a.Name}"/>
                </apex:column>
                <apex:column headerValue="Prénom">
                    <apex:inputField value="{!a.Prenom__c}"/>
                </apex:column> 
                                <apex:column headerValue="Né le">
                    <apex:inputField value="{!a.Date_de_naissance__c}"/>
                </apex:column>   
                                <apex:column headerValue="Lieu de naissance">
                    <apex:inputField value="{!a.Lieu_de_naissance__c}"/>
                </apex:column>   
                                <apex:column headerValue="Situation">
                    <apex:inputField value="{!a.Situation__c }"/>
                </apex:column>                          
            </apex:pageBlockTable>

            </apex:pageBlockSection>

            </apex:pageblock>
    </apex:form>
</apex:page>


public class insEnfant{

    public List<Enfants__c> accts {get; set;}

    public insEnfant(){
        accts = new List<Enfants__c>();
        accts.add(new Enfants__c());
    }

    public void addrow(){
        accts.add(new Enfants__c());
    }

    public PageReference save(){
        insert accts;
        PageReference home = new PageReference('/home/home.jsp');
        home.setRedirect(true);
        return home;
    }
}

But when I tried to save it I obtain this error:

Error: Unknown constructor 'insEnfant.insEnfant(ApexPages.StandardController controller)'
Create Apex method 'insEnfant.insEnfant(ApexPages.StandardController controller)'

As I am new to salesforce.com, can anyone please give me the code for this??

Upvotes: 0

Views: 3064

Answers (1)

Gareth McCaughan
Gareth McCaughan

Reputation: 19971

Take a look at http://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_extension.htm which explains that a controller extension needs to have a constructor that takes a StandardController as argument. (You've provided a constructor that takes no arguments.) There's some sample code on that page that you may find helpful.

Upvotes: 2

Related Questions