How to get the apex:inputText fields values into the apex controller class from visualforce page?

VF page having some apex:inputText fields and one custom button and on clicking of the button, the values in the apex:inputText field should be passed to the apex controller class to save it in the database.

Its possible to achieve using the below way.

Apex Class:

public with sharing class textInputsCont {

public String inputText1{get;set;} // input text1 value from visualforce page
public String inputText2{get;set;} // input text2 value from visualforce page
public void saveTextValue(){
Account  a = new Account();

a.TextField1__c =  inputText1;  // Field Assignment1
a.TextField2__c =  inputText2;  // Field Assignment2

insert  a; // DML Operations

Visualforce Page:

<apex:page showHeader="false" sidebar="False" controller="textInputsCont">
<apex:form >
Input Text1 <apex:inputText value="{!inputText1}"/>
Input Text2 <apex:inputText value="{!inputText2}"/>
<apex:commandButton value="save" action="{!saveTextValue}"/>

Account is a Standard Object – same way we can use with either standard object or custom object
TextField1__c and TextField2__c is a custom field from Account object.


Written by 

I am Sakthivel Madesh, a certified Salesforce Developer & Administrator working on Salesforce Technology since 2011. I am currently working in Techforce Services as Sr. Salesforce Developer. I have worked on multiple technologies Like PHP, Java, Salesforce, I am very passionate about Salesforce and to earn 13x Salesforce Certification. I love Trailhead for learning Salesforce Skill and Become a Trailhead Ranger too. I Love to Learn & Share my Salesforce knowledge to Salesforce Learners/Beginner using My Blog and Salesforce Community.

Leave a Reply