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
Parteek Goyal 3Parteek Goyal 3 

Error: Unknown constructor 'student.student()

Hi,

public class student{
    public Student__c lststudent{get;set;}
    public String str{get;set;}
    public student(ApexPages.StandardController sc){
        String studentid=sc.getID();
        if(studentid == null && studentid == ''){
            lststudent=[SELECT id from student__c where id=:studentid];
        }
        else{
            lststudent=new Student__c();
        }
        
    }
    public PageReference savemethod(){
        insert lststudent;
        if(str =='new'){
            lststudent=new Student__c();
            str=null;
        }
        return null;
    }
    public List<Student__c> getrecord(){
        List<Student__c> allrecord=[SELECT id,name__c,manager__c,address__c,email__c from Student__c];
        return allrecord;
    }
}

----------------------------------------

<apex:page Controller="student">
    <apex:form >
      <apex:pageBlock >
          <apex:pageBlockButtons >
              <apex:commandButton value="Save" action="{!savemethod}"/>
              <apex:commandButton value="Save and New" action="{!savemethod}"/>
              <apex:param id="name" value="new" assignTo="{!str}"/>
          </apex:pageBlockButtons>
          <apex:pageBlockSection columns="1">
              <apex:inputField value="{!lststudent.name}"/>
              <apex:inputField value="{!lststudent.Name__c}"/>
              <apex:inputField value="{!lststudent.Email__c}"/>
              <apex:inputfield value="{!lststudent.Phone__c}"/>
              <apex:inputField value="{!lststudent.Manager__c}"/>
              <apex:inputField value="{!lststudent.Address__c}"/>
          </apex:pageBlockSection>
      </apex:pageBlock>
    </apex:form>
    <apex:pageBlock title="Records">
        <apex:dataTable value="{!record}" var="r">
            <apex:column >
                <apex:outputLabel title="hh">Name</apex:outputLabel>
                {!r.Name__c}
            </apex:column>
        </apex:dataTable>
    </apex:pageBlock>
</apex:page>


this will show an error:
Error: Unknown constructor 'student.student()
and please also tell me how to set header name of a column when we show a list record on a page.
please help me
Best Answer chosen by Parteek Goyal 3
Deepak Kumar ShyoranDeepak Kumar Shyoran
This is because you are using a only Controller attribute on your VF page but in controller you have override your default constructor which should only be override in case if you were using a StandardController and an extension.

As it seems from your code your are using this page either on a detail page or on custom button to show a VF page , so simply modified first line of you vf page as shown below

Use this to remove above error
<apex:page StandardController="Student__c"  extensions="student" >

Use Apex:facet to show heder for column as shown below for your case

<apex:column >
   <apex:facet name="header">Name</apex:facet> 
  {!r.Name__c}           
</apex:column>