+ Start a Discussion
Mohammadasif SiddiquiMohammadasif Siddiqui 

I cant save record in table when I click on Save button

public class HospitalApex{

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

public HospitalApex( 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();     
<apex:page standardController="Hospital__c" extensions="HospitalApex">
<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>

I want to save record entered in text field in table but when i click on Save button, nothing happens
ANUTEJANUTEJ (Salesforce Developers) 
Hi Mohammadasif,

In case if you want to debug you can set up the debug logs and you can then recreate the steps to check the flow if your code and correct where the issue is occuring.

Apart from the above I also found the below link for similar implementation can you please check it out and in case if it helps can you please choose this as the best answer so that it can be used by others in the future.

>>  https://salesforce.stackexchange.com/questions/32593/visualforce-overriding-save-button-behavior

Naval Sharma4Naval Sharma4

Give an Id to the "apex:pageBlock" at line no. 3. For example we gave it "mainForm". After doing that you should try adding mainSection, mainForm in the rerender performing by CommandButton. Looks like records are being saved but you're not seeing any changes at the UI level on your page.