Im having a VF page it has some text fields and one button . On clicking the button , the values in the text field should be passed to the controller class to save in the database . Can this be achieved . If yes , direct me .


i think this is one way

<apex:page showHeader="false" sidebar="False" controller="textInputsCon">

<apex:form >

   Input Text1 <apex:inputText value="{!inputText1}"/>
   Input Text2 <apex:inputText value="{!inputText2}"/>

    <apex:commandButton value="save" action="{!saveList}"/>


    public with sharing class textInputsCon {

     public String inputText1{get;set;} // input text1 value  from vf
     public String inputText2{get;set;} // input text2 value  from vf

      public void saveList(){

        salesObj  salesObjInst = new salesObj(); //  Either salesObj is standard or custom object

        salesObj.field1 =  inputText1;  // Field Assignment
        salesObj.field2 =  inputText2;  // Field Assignment

        insert  salesObj; // DML Operations



Another way , if you want call save action from the command button with out navigating to controller , you can use java script remoting.

Define one java script function same as a object, and call this function from the onclick event of button, check the below link


| improve this answer | |


You can reference the above document link to understand the concept of getter and setter in the sfdc.

Getter fetches the data from controller on to the visualforce page

Setters passes data from the visualforce page to apex controller class

Action methods are the methods invoked on the click of command button or link.

The order of execution is

1)All getters run first 2)Before your action methods all the setters get executed .


Refer the workbook to get started with some basic examples and below wiki guide


| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.