[SalesForce] Make a button on visualforce update the records in an object

I have a custom object named "O1". It have 5 fields, namely

1.) Address

2.) Name

3.) Email

4.) Phone Number

5.) Age

I have created a custom VF page and shown these fields on that page. Now, I want to assign a save button which will save the data entered by user here into the object "O1".

How can I do so? Is it called anything? I can look it up myself, just need someone to point me in right direction.

thank you

Best Answer

If these are all fields that live directly on your custom object, then you can just use the standard controller on your custom object, and then invoke the standard {!save} function on a commandButton/link/etc

Something like this... (Note, have not attempted to compile code, wrote on the fly):

<apex:page standardController="O1__c">
    <apex:PageBlock>
        <apex:PageBlockSection>
            <apex:form>
                <apex:inputField value="{!O1__c.Name}" />
                <apex:inputField value="{!O1__c.Email__c}" />
                ... etc
                <apex:commandButton value="Save" action="{!save}" />
            </apex:form>
        </apex:PageBlockSection>
    </apex:PageBlock>
</apex:Page>

See the Salesforce Documentation on StandardController Methods for more information on all methods available when using standardController:

https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/apex_ApexPages_StandardController_methods.htm

Related Topic