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
kcnmaheshkcnmahesh 

How to save a record using VisualforcePage

Hi..,

 

I override Standard Button "NEW" and i created one visualforce page for that NEW button.

In visualforce page , just i inserted all fields to save a record.

I used standard buttons Called SAVE and CANCEL , for saving record after inputting all required values.

Its working fine , but record is not saving into database.

Can anyone help me ?

 

Also i am posting my code.

 

VisualforcePage:

 

<apex:page standardController="Why_Why_Analysis__c" extensions="WhyAnalysisController">
<apex:form >
<apex:pageBlock >
<apex:pageMessages ></apex:pageMessages>
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}"/>
<apex:commandButton value="Cancel" action="{!cancel}"/>
</apex:pageBlockButtons>
<br/>
Why? : <apex:inputfield value="{!Why_Why_Analysis__c.Name}"/>
<br/>Fishbone Analysis : <apex:inputField value="{!Why_Why_Analysis__c.Fishbone_Analysis__c}"/>
Root Cause : <apex:inputField value="{!Why_Why_Analysis__c.Root_Cause__c}"/>
Currency : <apex:inputField value="{!Why_Why_Analysis__c.CurrencyIsoCode}"/>
</apex:pageBlock>
</apex:form>
</apex:page>

Controller...

public class WhyAnalysisController {

    public WhyAnalysisController(ApexPages.StandardController controller) {

    }

    public pageReference save(){

              return null;
}
  
}

 
tukmoltukmol

you see that controller that is passed to the constructor? Call its save() method, i.e.

public PageReference save() {

    return this.controller.save();

}

Scott_VSScott_VS

Standard controllers already come with a default save() and cancel() function. By adding the extension on this page, you're overriding the default save() function to:

 

public pageReference save(){
      return null;
}

 Which does nothing.

 

Remove the extension from your page and it should revert to the default save() function.

harsha__charsha__c

You can get that by the following code:

 Solution 1 :  With using the extensions

 

Page:

 

<apex:page standardController="Why_Why_Analysis__c" extensions="WhyAnalysisController">
<apex:form >
<apex:pageBlock >
<apex:pageMessages ></apex:pageMessages>
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}"/>
<apex:commandButton value="Cancel" action="{!cancel}"/>
</apex:pageBlockButtons>
<br/>
Why? : <apex:inputfield value="{!objWhy_Why_Analysis__c.Name}"/>
<br/>Fishbone Analysis : <apex:inputField value="{!objWhy_Why_Analysis__c.Fishbone_Analysis__c}"/>
Root Cause : <apex:inputField value="{!objWhy_Why_Analysis__c.Root_Cause__c}"/>
Currency : <apex:inputField value="{!objWhy_Why_Analysis__c.CurrencyIsoCode}"/>
</apex:pageBlock>
</apex:form>
</apex:page>

 Controller:

public with sharing class WhyAnalysisController 
{
	public Why_Why_Analysis__c objWhy_Why_Analysis__c{get;set;}
	
	public xyzClass(ApexPages.StandardController controller)
	{
		objWhy_Why_Analysis__c = new Why_Why_Analysis__c();
	}
	
	public void save()
	{
		insert objWhy_Why_Analysis__c;
		
	}
	
	public void cancel()
	{
		
	}

}

 Solution 2 : Without using the extensions (no need of controller)

 

<apex:page standardController="Why_Why_Analysis__c">
<apex:form >
<apex:pageBlock >
<apex:pageMessages ></apex:pageMessages>
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}"/>
<apex:commandButton value="Cancel" action="{!cancel}"/>
</apex:pageBlockButtons>
<br/>
Why? : <apex:inputfield value="{!Why_Why_Analysis__c.Name}"/>
<br/>Fishbone Analysis : <apex:inputField value="{!Why_Why_Analysis__c.Fishbone_Analysis__c}"/>
Root Cause : <apex:inputField value="{!Why_Why_Analysis__c.Root_Cause__c}"/>
Currency : <apex:inputField value="{!Why_Why_Analysis__c.CurrencyIsoCode}"/>
</apex:pageBlock>
</apex:form>
</apex:page>

 

Mark it as a solution, If this resolves your problem.......