+ Start a Discussion
Mohammadasif SiddiquiMohammadasif Siddiqui 

Unknown constructor 'HospitalController.HospitalController()'

<apex:page controller="HospitalController" >
<apex:form >
<apex:pageBlock >
  <apex:pageMessages id="showmsg"></apex:pageMessages>  
<apex:pageBlockSection >
<apex:pageBlockSectionItem >
  Hospital Name : 
<apex:inputField value="{!hosp.Name}"/>  
 <apex:pageBlockSectionItem >
Account Name :  
 <apex:inputField value="{!hosp.Account__c}"/>
    <apex:pageBlockButtons >
<apex:commandButton action="{!insertNewItem}" value="Save" rerender="showmsg"/>   

<apex:pageBlockTable value="{! insertedrecord }" var="ct" id="mainSection">
    <apex:column headerValue="Hospital Name">"{! ct.Name }"</apex:column>
    <apex:column headerValue="Account Name">"{! ct.Account__c }"</apex:column>

public class HospitalController{

    public Hospital__c hosp{get;set;}
    public Hospital__c insertedrecord{get;set;}

public HospitalController( ApexPages.StandardController sc ) {
        this.hosp= (Hospital__c)sc.getRecord(); }
  public void insertNewItem() {
if(hosp.Name == NULL || hosp.Name == '' )
   ApexPages.addmessage(new ApexPages.message(ApexPages.severity.FATAL,'Please enter Something'));   
      insert hosp;
      id insertedrecordid = hosp.Id;
      insertedrecord = [Select Name, Account__c  from Hospital__c where Id = :insertedrecordid  ];
        hosp = new Hospital__c();     

I am getting error 
Unknown constructor 'HospitalController.HospitalController()'

Please help me
ShirishaShirisha (Salesforce Developers) 


Can you please check the below document to get more details:



Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future.

Warm Regards,
Shirisha Pathuri
Devi ChandrikaDevi Chandrika (Salesforce Developers) 
Hi ,
This error might be because of the constructor in your apex class.If you are using your apex class as extension only then you have to pass ApexPages.StandardController as an argument to contructor.Please try by removing the argument from constructor.

Please refer below links which might help you in this

Hope this helps you
Let me know if this helps you. Kindly mark it as solved so that it may help others in future.

Thanks and Regards