How to save the value of a form in custom object of salesforce

my apexpage and controller is

<apex:page Controller="test_validation">
  <apex:form >
      <apex:pageBlock >
              <apex:commandButton action="{!Save}" value="Save"/>

              <apex:inputField label="Summary" value="{!testvalidation.Sumary__c}"/>
              <apex:inputField value="{!testvalidation.Class__c}" label="Class"/>

public class test_validation {
    public test_validation__c testvalidation{get;set;}
    public test_validation__c vartest{get;set;}

    public PageReference Save(){
        vartest=new test_validation__c();
        insert vartest;
        return null;

i want to know how to access vf input field in apex class.


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You save the same instance that the Visualforce page is bound to. When the form is submitted the platform updates the fields and then you can save the instance:

public class test_validation {
    public test_validation__c testvalidation{get;set;}
    public test_validation() {
        testvalidation = new test_validation__c();
    public PageReference Save(){
        insert testvalidation;
        return null;

This Visualforce Workbook explains this and many other important concepts.

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x