0

Hi I'm new building Visualforce Pages with Controllers and I'm sure I'm missing something stupid here but I'm getting the following Error:

Error: Unknown constructor 'AuditTeamControllerExtension.AuditTeamControllerExtension(AuditController controller)

This are my custom controllers:

    public class AuditController {

/* Audit__c Object Section Begin*/    

    public Audit__c Audit {get; set;}

    public AuditController() {
        Id id = ApexPages.currentPage().getParameters().get('id');
        String newID = '\''+id+'\'';
        system.debug('Reference ID: '+newID);
        Audit = (id == null) ? new Audit__c() : 
            Database.query('SELECT ' + String.join(new List<String>(Schema.getGlobalDescribe().get('Audit__c').getDescribe().fields.getMap().keySet()), ',') + ' FROM Audit__c ' + 'WHERE ' + 'Id='+newID);
    }

    public PageReference save() {
        try {
            upsert(Audit);
        } catch(system.DmlException e) {
            ApexPages.addMessages(e);
            return null;
        }
        //After sucessful Save, navigate to the custom view page
        PageReference redirectSuccess = ApexPages.currentPage();
        return redirectSuccess;
    }
/* Audit__c Object Section End */


}

Extension:

    public class AuditTeamControllerExtension {

    public List<Audit_Team__c> AuditTeam {get; set;}

    public AuditTeamControllerExtension() {
        AuditTeam = [SELECT Id, Name, Audit__c, Auditor_Name__c, CreatedById, Role__c
                                      FROM Audit_Team__c
                                      WHERE Audit__c= :ApexPages.currentPage().getParameters().get('id')];
    }



}

VF Markup:

    <!-- Remember that the format for record ID is the following: https://salesforce_instance/apex/myPage?id=001D000000IRt2 -->

<apex:page controller="AuditController" extensions="AuditTeamControllerExtension" lightningStylesheets="true" showHeader="true" id="MainPage">
<apex:form >
    <h2>Hello {!$User.FirstName} {!$User.LastName}, welcome back!</h2>

   <apex:pageblock title="Audit">
       <apex:pageBlockSection columns="3">
           <apex:OutputField value="{! Audit.Name }"/>
           <apex:OutputField value="{! Audit.Type__c }"/>
           <apex:OutputField value="{! Audit.Status__c }"/>
           <apex:OutputField value="{! Audit.Account__c }"/>
           <apex:OutputField value="{! Audit.Department__c }"/>
           <apex:OutputField value="{! Audit.Stage__c }"/>
           <apex:OutputField value="{! Audit.Title__c }"/>
       </apex:pageBlockSection>

<!-- This is the edit part
       <apex:inlineEditSupport event="onClick" showOnEdit="saveButton, cancelButton" hideOnEdit="editButton"/>
           <apex:pageBlockButtons >
           <apex:commandButton value="Edit" action="{!save}" id="editButton"/>
           <apex:commandButton value="Save" action="{!save}" id="saveButton"/>
           <apex:commandButton value="Cancel" action="{!cancel}" id="cancelButton"/>
           </apex:pageBlockButtons>
-->

   </apex:pageblock>

   <apex:pageBlock >
       <apex:tabPanel switchType="client" selectedTab="" id="theTabPanel">
            <apex:tab label="Audit" name="Audit" id="tabAudit">

                <apex:pageBlock >
                    <apex:pageBlockSection columns="3">
                        <apex:OutputField value="{! Audit.Account__c}"/>
                        <apex:OutputField value="{! Audit.Audit_Category__c }"/>
                        <apex:pageBlockSectionItem ></apex:pageBlockSectionItem>
                        <apex:OutputField value="{! Audit.External_Auditor__c }"/>
                        <apex:OutputField value="{! Audit.Auditor_Names__c }"/>
                        <apex:OutputField value="{! Audit.OwnerId }"/>
                        <apex:OutputField value="{! Audit.Start_Date__c }"/>
                        <apex:OutputField value="{! Audit.End_Date__c }"/>
                    </apex:pageBlockSection>
                    <apex:pageBlockSection title="Audit" columns="3">
                        <apex:OutputField value="{! Audit.Account__c }"/>
                        <apex:OutputField value="{! Audit.Auditee_Contact__c }"/>
                        <apex:OutputField value="{! Audit.Department__c }"/>
                        <apex:OutputField value="{! Audit.Location__c }"/>
                        <apex:OutputField value="{! Audit.Business_Unit__c }"/>
                    </apex:pageBlockSection>
                    <apex:pageBlockSection title="Description" columns="1">
                        <apex:OutputField value="{! Audit.Title__c }"/>
                        <apex:OutputField value="{! Audit.Audit_Scope__c }" label="Audit Scope/Description"/>
                    </apex:pageBlockSection>
                    <apex:pageBlockSection title="Follow-up Audit__c" columns="3">
                        <apex:OutputField value="{! Audit.Follow_up_Required__c }"/>
                        <apex:OutputField value="{! Audit.Follow_up_Date__c }"/>
                    </apex:pageBlockSection>
                </apex:pageBlock>
            </apex:tab>

            <apex:tab label="Audit Team" name="AuditTeam" id="tabAuditTeam">

                <apex:pageBlock >
                    <apex:pageBlockTable columns="3" rows="10" title="Audit Team" value="{!AuditTeam}" var="at">
                        <apex:column value="{!at.Auditor_Name__c}"/>
                        <apex:column value="{!at.Role__c}"/>
                        <apex:column value="{!at.CreatedById}"/>
                    </apex:pageBlockTable>
                </apex:pageBlock>

            </apex:tab>

            <apex:tab label="Files" name="Files" id="tabFiles">content for tab one</apex:tab>
            <apex:tab label="Audit Checklist" name="AuditChecklist" id="tabAuditChecklist">content for tab two</apex:tab>
            <apex:tab label="Finding" name="Finding" id="tabFinding">content for tab one</apex:tab>
            <apex:tab label="Objective Evidence" name="ObjectiveEvidence" id="tabTwo">content for tab two</apex:tab>
            <apex:tab label="Audit Response" name="AuditResponse" id="tabAuditResponse">content for tab one</apex:tab>
            <apex:tab label="Implementation" name="Implementation" id="tabImplementation">content for tab two</apex:tab>
            <apex:tab label="Record Activity" name="RecordActivity" id="tabRecordActivity">content for tab one</apex:tab>
       </apex:tabPanel>
   </apex:pageBlock>


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

2 Answers 2

3

An extension controller needs reference to the "standard controller" to be accepted in its constructor. Update your code to replace the extension controller's constructor with:

public AuditTeamControllerExtension(AuditController controller) {

even if you don't then use that controller. Note that it is from the controller that you would normally obtain the ID of the object for which the page has been requested.

0

You are missing the constructor required for your Extension.

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.

You will need to define a constructor in your extension as below:

public AuditTeamControllerExtension(ApexPages.StandardController stdController) {
    ...
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.