-1

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 {
        get;
        set;
    }

    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:form>
        <apex:pageBlock>
            <apex:pageBlockSection>
                <apex:inputField value="{!book.Name}" />
                <apex:inputField value="{!book.amount__c}" />
                <apex:inputField value="{!book.color__c}" />
            </apex:pageBlockSection>
            <apex:pageBlockButtons>
                <apex:commandButton action="{!insertNewItem}" value="save" />
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>
  • 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
0

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.