3

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

4

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

4
  • I am already doing this. But, it only refreshes the page. doesn't save the input – Anony-Kun Jul 24 '16 at 14:47
  • Is your commandButton inside the same <apex:form> as your form fields? If your button doesn't live inside of the same form, it won't save any of the data in that form. Salesforce should commit all changes on the page before invoking Save, so thats my best guess without seeing your code. – Morgan Marchese Jul 24 '16 at 14:52
  • I just checked and my button was indeed outside my form. Thank you. – Anony-Kun Jul 24 '16 at 15:03
  • Nice, glad that worked out for you! – Morgan Marchese Jul 24 '16 at 15:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.