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
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'));   
}
 else
 {     
      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>
    
 <apex:pageBlockSectionItem >
Account Name :  
 <apex:inputField value="{!hosp.Account__c}"/>
</apex:pageBlockSectionItem>  
</apex:pageBlockSection>   
  
    <apex:pageBlockButtons >
    
<apex:commandButton action="{!insertNewItem}" value="Save" rerender="showmsg"/>   

</apex:pageBlockButtons>
    
<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>
</apex:pageBlockTable>    

</apex:pageBlock>
</apex:form>
</apex:page>
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

Regards,
Anutej
Naval Sharma4Naval Sharma4
Hi,

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.