function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
shephalishephali 

how to insert value in custom object fields via VF page's save button click

Best Answer chosen by shephali
KaranrajKaranraj
Uss your custom object in the standard controller of visualforce page, include what are the fields you want to have in visualforce page and add the save button.
<apex:page sidebar="false" standardController="ObjectName__c">
    <apex:form >
    <apex:pageBlock title="Account Summary">
        <apex:pageBlockSection >
            Name: <apex:inputfield value="{! ObjectName__c.Name }" /> <br/>
            Phone: <apex:inputfield value="{! ObjectName__c.Phone}" /> <br/>
        </apex:pageBlockSection>
    <apex:pageBlockButtons >
     <apex:commandButton action="{!save}" value="Save"/>
    </apex:pageBlockButtons>
    </apex:pageBlock>
    </apex:form>
</apex:page>

I strongly encourage you to take a look into the Trailhead modules which really helps you understand & learn about salesforce platform easily
https://developer.salesforce.com/trailhead

 

All Answers

Chandra Sekhar CH N VChandra Sekhar CH N V
Use standard controller of the custom object along with the input fields of the object you want to insert on the VF page.The save action on button will automatically create records in objects. Below is a sample code:

<apex:page standardController="obj">
    <apex:form >
        <apex:pageBlock >
             <apex:pageBlockSection >
     <apex:inputField value="{!obj.field1}"/>
     <apex:inputField value="{!obj.field2}"/>
     ......
     <apex:commandButton action="{!save}" value="Save"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>        
</apex:page>
KaranrajKaranraj
Uss your custom object in the standard controller of visualforce page, include what are the fields you want to have in visualforce page and add the save button.
<apex:page sidebar="false" standardController="ObjectName__c">
    <apex:form >
    <apex:pageBlock title="Account Summary">
        <apex:pageBlockSection >
            Name: <apex:inputfield value="{! ObjectName__c.Name }" /> <br/>
            Phone: <apex:inputfield value="{! ObjectName__c.Phone}" /> <br/>
        </apex:pageBlockSection>
    <apex:pageBlockButtons >
     <apex:commandButton action="{!save}" value="Save"/>
    </apex:pageBlockButtons>
    </apex:pageBlock>
    </apex:form>
</apex:page>

I strongly encourage you to take a look into the Trailhead modules which really helps you understand & learn about salesforce platform easily
https://developer.salesforce.com/trailhead

 
This was selected as the best answer
shephalishephali
Thank you Chandra sekhar and Karanraj !! It worked
Chandra Sekhar CH N VChandra Sekhar CH N V
Thanks Shepali for the response.


As a common practice, if your question is answered, please choose 1 best answer.
You can alos give every answer a thumb up if that answer is helpful to you.

This will help future users determine what answers are useful and which one was the best in resoution.
 
Nagaraju Mogili 31Nagaraju Mogili 31
How can we save the values in to database using controller and vf page, not with the single vf page
srilekha kowtikwarsrilekha kowtikwar
I want to save custom field value in account object to database using vf page and controller how can i do that