I want to insert records after clicking the create button.In my code the record are inserted.but i want to insert record after clicking "create" button

public class ItemController {

    public book__c book {

    public ItemController() {
        book = new book__c();

    public PageReference insertNewItem() {

        insert book;
        //reset public property for new insert
        book = new book__c();

        return null;

Visualforce page:

<apex:page controller="ItemController">
                <apex:inputField value="{!book.Name}" />
                <apex:inputField value="{!book.amount__c}" />
                <apex:inputField value="{!book.color__c}" />
                <apex:commandButton action="{!insertNewItem}" value="save" />
  • Where is your create button? If it exists, just set the action="{!insertNewItem}" for that as you have done for the save button – highfive Sep 7 '15 at 10:28
  • 2
    Or just change the value="Save" to value="Create". Whoa! You now have a create button! – Santanu Halder Sep 7 '15 at 10:30

I would suggest you to rather change the value of save button to the create as ur code is working correct as per ur requirement so the functionality of the code remains same. Thanks

| improve this answer | |

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.