I've created a visualforce page and custom component that is referencing the same record, in which I've passed the record from the standardController to the custom component via apex:atttribte.

I have input fields on both the Main Visualforce page and Custom Component page but when I'm trying to save the record(The save button and method is in the main page) the update from the custom component is not being saved.

Here's my code:

Main Visualforce Page:

  <apex:page standardController="Account" extensions="AccountTestController">
                <apex:pageBlock title="Page Section">
                        <apex:commandButton action="{!saveAcc}" value="Save"/>
                        <apex:inputField value="{!acc.LastName}" required="true"/> 
            <c:AccoutnComponent accRecord="{!acc}"/>

Main Page Controller:

public class AccountTestController {

    public Account acc {get; set;}

    public AccountTestController(ApexPages.StandardController stdController) {
        if(stdController.getID() != null) {
            acc = [SELECT Id, LastName,Name, Phone, isPersonAccount FROM Account WHERE Id=: stdController.getID()];
        } else {
            acc = new Account();


    public PageReference saveAcc() {
        upsert acc;

        return new PageReference('/');


Custom Component Page:

<apex:component controller="AccountComponentController">
    <apex:attribute name="accRecord" assignTo="{!pageAcc}" description="Account from Main Page" type="Account"/>
        <apex:pageBlock title="Component Section">
                <apex:outputField value="{!pageAcc.Name}"/>
                <apex:inputField value="{!pageAcc.Phone}" required="true"/>

Custom Component Controller:

public class AccountComponentController {
    public Account pageAcc {get; set;}

    public AccountComponentController() {


Here's how it looks


It seems that I was able to retrieve the values from the main page since the Last Name is being reflected from the component page, it's just that the update from the field in the component section is not being saved upon clicking the Save button from the Main Page.

Am I doing something wrong here? Enlighten me please.


  • Hi Mohith, This is already all of the code.
    – sfdx
    Commented Aug 3, 2015 at 0:02
  • y dont u use the same controller for the page and the component ? Commented Aug 3, 2015 at 0:29
  • 1
    Somehow you have added two different forms ?One on Page and other on component .Get rid of one of those to see if it helps .Thanks Commented Aug 3, 2015 at 0:34
  • And it worked! Thanks!! Combined them into a single form, worked like magic! Sweet! Cheers Mohith!
    – sfdx
    Commented Aug 3, 2015 at 1:04

2 Answers 2


Always try avoiding duplicate forms in your maarkup.The code has two forms here and hence the issue .Use single form always .


You can leave the Form tag on both the main Visualforce page and the Component. Just move the call to the component within the Form tag of the main page not after the tag.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .