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
kumar.fdc81.3902978579608325E12kumar.fdc81.3902978579608325E12 

record is not saving

Hi all,

I am clicking on save button record is not inserting...

VF Page:-
------------

<apex:page standardController="Employee1__c" tabStyle="Employee1__c" extensions="Thirdware">
 <apex:form >
  <apex:pageBlock id="first">
   <apex:pageblockSection title="First Page">
    <apex:inputfield value="{!Employee1__c.FirstName__c}" />
    <apex:inputfield value="{!Employee1__c.LastName__c}" />
   </apex:pageblockSection>
 
   <apex:outputPanel id="second">
   <apex:outputPanel rendered="{!show}">
   <apex:pageBlockSection title="Second page">
   
    <apex:inputfield value="{!Employee1__c.Employee2__c}" />
    <apex:inputfield value="{!Employee1__c.Picklist__c}" /> 
    <apex:commandButton value="Approved" />
    <apex:commandButton value="Rejected" /> 
    </apex:pageBlockSection>
    </apex:outputPanel>   
    </apex:outputPanel>
 
 <apex:pageBlockButtons location="Bottom">
  <apex:actionRegion >
   <apex:commandButton value="Save" action="{!savedata}">
   <apex:actionSupport reRender="second" event="onchange"/>
   </apex:commandButton>
   </apex:actionRegion>
  </apex:pageBlockButtons>
  </apex:pageBlock>
 </apex:form>
</apex:page>


Apex class:-
----------------
public with sharing class Thirdware {

    public Boolean show{get;set;}
    public string LastName{set;get;}
    public string FirstName{set;get;} 
    public Employee1__c emp {set;get;} 
    
    public Thirdware(ApexPages.StandardController controller) {
     show = false;
    }    
    
    public void savedata(){
     emp = new Employee1__c();
     emp.FirstName__c = FirstName;
     emp.LastName__c = LastName;
     try{
     insert emp;
    }catch(Exception e){
   }
   }
    public boolean Save(){
    
     show = true;
     return null;
    }    
}


Regards
Sam
Best Answer chosen by kumar.fdc81.3902978579608325E12
Anoop yadavAnoop yadav
Hi,
Try with the below Code.
public with sharing class Thirdware {

	public Boolean show{get;set;}
	public string LastName{set;get;}
	public string FirstName{set;get;} 
	public Employee1__c emp {set;get;} 
    
    public Thirdware(ApexPages.StandardController controller) {
		emp = new Employee1__c();
        show = false;
    }    
    
    public void savedata(){     
		emp.FirstName__c = FirstName;
		emp.LastName__c = LastName;
		
		try{
			insert emp;
		}catch(Exception e){}
    }
    
	public boolean Save(){
		show = true;
		return null;
    }    
}
 
<apex:page standardController="Employee1__c" tabStyle="Employee1__c" extensions="Thirdware">
 <apex:form >
  <apex:pageBlock id="first">
   <apex:pageblockSection title="First Page">
    <apex:inputText value="{!FirstName}" />
    <apex:inputText value="{!LastName}" />
   </apex:pageblockSection>
 
   <apex:outputPanel id="second">
   <apex:outputPanel rendered="{!show}">
   <apex:pageBlockSection title="Second page">
   
    <apex:inputfield value="{!Employee1__c.Employee2__c}" />
    <apex:inputfield value="{!Employee1__c.Picklist__c}" /> 
    <apex:commandButton value="Approved" />
    <apex:commandButton value="Rejected" /> 
    </apex:pageBlockSection>
    </apex:outputPanel>   
    </apex:outputPanel>
 
 <apex:pageBlockButtons location="Bottom">
  <apex:actionRegion >
   <apex:commandButton value="Save" action="{!savedata}">
   <apex:actionSupport reRender="second" event="onchange"/>
   </apex:commandButton>
   </apex:actionRegion>
  </apex:pageBlockButtons>
  </apex:pageBlock>
 </apex:form>
</apex:page>


 

All Answers

Anoop yadavAnoop yadav
Hi,
Try with the below Code.
public with sharing class Thirdware {

	public Boolean show{get;set;}
	public string LastName{set;get;}
	public string FirstName{set;get;} 
	public Employee1__c emp {set;get;} 
    
    public Thirdware(ApexPages.StandardController controller) {
		emp = new Employee1__c();
        show = false;
    }    
    
    public void savedata(){     
		emp.FirstName__c = FirstName;
		emp.LastName__c = LastName;
		
		try{
			insert emp;
		}catch(Exception e){}
    }
    
	public boolean Save(){
		show = true;
		return null;
    }    
}
 
<apex:page standardController="Employee1__c" tabStyle="Employee1__c" extensions="Thirdware">
 <apex:form >
  <apex:pageBlock id="first">
   <apex:pageblockSection title="First Page">
    <apex:inputText value="{!FirstName}" />
    <apex:inputText value="{!LastName}" />
   </apex:pageblockSection>
 
   <apex:outputPanel id="second">
   <apex:outputPanel rendered="{!show}">
   <apex:pageBlockSection title="Second page">
   
    <apex:inputfield value="{!Employee1__c.Employee2__c}" />
    <apex:inputfield value="{!Employee1__c.Picklist__c}" /> 
    <apex:commandButton value="Approved" />
    <apex:commandButton value="Rejected" /> 
    </apex:pageBlockSection>
    </apex:outputPanel>   
    </apex:outputPanel>
 
 <apex:pageBlockButtons location="Bottom">
  <apex:actionRegion >
   <apex:commandButton value="Save" action="{!savedata}">
   <apex:actionSupport reRender="second" event="onchange"/>
   </apex:commandButton>
   </apex:actionRegion>
  </apex:pageBlockButtons>
  </apex:pageBlock>
 </apex:form>
</apex:page>


 
This was selected as the best answer
kumar.fdc81.3902978579608325E12kumar.fdc81.3902978579608325E12
Hi Anoop,

It's working but i have a doubt

Why you talken "Input Text" beyond of "InputField".

Thanks
sam
Anoop yadavAnoop yadav
Hi,
FirstName and LastName are string variable in your controller.
that is the reason I am taking as InputText.
If you do not want to use InputText, you should not use string variables.