+ Start a Discussion
sumanforce@gmail.comsumanforce@gmail.com 

How to store data

Hi Friends, I have designed a form using visualforce. After filling the form, i attached a controller (Apex Class). I need to save the data to the database. Can you please help me Thanks suman
Best Answer chosen by Admin (Salesforce Developers) 
anjisalesforce@gmail.comanjisalesforce@gmail.com

Hi Suman,

 

Use the below code sample as reference

 

<apex:page controller="savecontact">

    <apex:form>

<apex:panelgrid columns="2">

        LastName:<apex:inputText value="{!lastname}" />

        EmailId:<apex:inputText value="{!mailid}" /> 

<apex:commandbutton value="Save" Action="{!insertcontact}" />

</apex:panelgrid>

</apex:form>

</apex:page>////////////////////////// Controller /////////////////////

Public class savecontact

{

Public string lastname{get;set;}

Public string mailid{get;set;}

Public void insertcontact()

{

Contact cont=new contact (lastname=lastname, email=mailid);

Insert cont;

}

}

All Answers

AmitSahuAmitSahu

You are using a custom controller so hopefully you can write a save method in your controller to save the data to the object.

 

Regards,

J

Navatar_DbSupNavatar_DbSup

Hi,

 

Use the below code sample as reference

 

<apex:page controller="Test">

    <apex:form >

        LastName:<apex:inputText value="{!lname}" /><br/>

        EmailId:<apex:inputText value="{!Conemail}" /><br/>

 

<apex:commandbutton value="Save" Action="{!JustSave}" />

</apex:form>

</apex:page>////////////////////////// Controller /////////////////////

Public class Test

{

Public string lname{get;set;}

Public string Conemail{get;set;}

Public void JustSave()

{

Contact con=new contact (lastname=lname, email=Conemail);

Insert con;

}

}

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

anjisalesforce@gmail.comanjisalesforce@gmail.com

Hi Suman,

 

Use the below code sample as reference

 

<apex:page controller="savecontact">

    <apex:form>

<apex:panelgrid columns="2">

        LastName:<apex:inputText value="{!lastname}" />

        EmailId:<apex:inputText value="{!mailid}" /> 

<apex:commandbutton value="Save" Action="{!insertcontact}" />

</apex:panelgrid>

</apex:form>

</apex:page>////////////////////////// Controller /////////////////////

Public class savecontact

{

Public string lastname{get;set;}

Public string mailid{get;set;}

Public void insertcontact()

{

Contact cont=new contact (lastname=lastname, email=mailid);

Insert cont;

}

}

This was selected as the best answer
sumanforce@gmail.comsumanforce@gmail.com

Hi Anji,

Thanks for the help.

 

I have executed the code..but how to see where the lastname, email are stored.

 

Please help

 

Thanks

Venkat