You need to sign in to do that
Don't have an account?
Shivendra Singh Pawar
Hello All, I am trying to pass the Input field value from Visualforce page to apex controller class. Please let me know how to capture the value.
We have a custom Object and fields,
What I want is to fill the form and insert a record to the Student Object.
Someone, please help me..!!
Below is the Code:
Visualforce page :
<apex:pageBlockButtons >
<apex:commandButton action="{!insertField}" value="Save"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Crud Operation Using Apex and Visualforce" columns="2" collapsible="true">
<apex:inputField value="{!stud.Name}"/>
<apex:inputField value="{!stud.shivendra__Phone__c}"/>
<apex:inputField value="{!stud.shivendra__Email__c}"/>
<apex:inputField value="{!stud.shivendra__Age__c}"/>
<apex:inputField value="{!stud.shivendra__State__c}"/>
<apex:inputField value="{!stud.shivendra__City__c}"/>
</apex:pageBlockSection>
</apex:pageBlock>
Apex Class Code:
public class crud1 {
// Instance to use Fields API in a a VF Page
public shivendra__Student__c stud {get; set;}
public String Name {get; set;}
public String Email {get; set;}
public String Age {get; set;}
public String Phone {get; set;}
public String State {get; set;}
public String City {get; set;}
//Function used to Insert a Record
public PageReference insertField(){
shivendra__Student__c studentRecord = new shivendra__Student__c();
studentRecord.name = Name;
studentRecord.shivendra__Phone__c = stud.shivendra__Phone__c;
studentRecord.shivendra__Email__c = Email;
studentRecord.shivendra__Age__c = Age;
studentRecord.shivendra__State__c = State;
studentRecord.shivendra__City__c = City;
insert studentRecord;
pagereference ref = new pagereference('/apex/CrudOperations1');
ref.setredirect(true);
return ref;
}
}
What I want is to fill the form and insert a record to the Student Object.
Someone, please help me..!!
Below is the Code:
Visualforce page :
<apex:pageBlockButtons >
<apex:commandButton action="{!insertField}" value="Save"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Crud Operation Using Apex and Visualforce" columns="2" collapsible="true">
<apex:inputField value="{!stud.Name}"/>
<apex:inputField value="{!stud.shivendra__Phone__c}"/>
<apex:inputField value="{!stud.shivendra__Email__c}"/>
<apex:inputField value="{!stud.shivendra__Age__c}"/>
<apex:inputField value="{!stud.shivendra__State__c}"/>
<apex:inputField value="{!stud.shivendra__City__c}"/>
</apex:pageBlockSection>
</apex:pageBlock>
Apex Class Code:
public class crud1 {
// Instance to use Fields API in a a VF Page
public shivendra__Student__c stud {get; set;}
public String Name {get; set;}
public String Email {get; set;}
public String Age {get; set;}
public String Phone {get; set;}
public String State {get; set;}
public String City {get; set;}
//Function used to Insert a Record
public PageReference insertField(){
shivendra__Student__c studentRecord = new shivendra__Student__c();
studentRecord.name = Name;
studentRecord.shivendra__Phone__c = stud.shivendra__Phone__c;
studentRecord.shivendra__Email__c = Email;
studentRecord.shivendra__Age__c = Age;
studentRecord.shivendra__State__c = State;
studentRecord.shivendra__City__c = City;
insert studentRecord;
pagereference ref = new pagereference('/apex/CrudOperations1');
ref.setredirect(true);
return ref;
}
}
Greetings to you!
Below is the sample code which I have tested in my org and it is working fine. Kindly modify the code as per your requirement.
Visualforce:
Controller:
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas
All Answers
Greetings to you!
Below is the sample code which I have tested in my org and it is working fine. Kindly modify the code as per your requirement.
Visualforce:
Controller:
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas
Thanks for the code.
It works fine.
Thanks
Shivendra Singh Pawar