below is my code, I have created an VF Component/VFP/Controller

My question is: How can I save the value of the <apex:inputField in the VF Component


  <apex:attribute name="fname" description="fn" type="myCustomObject__c" required="true" /> 
  <apex:attribute name="mname" description="mn" type="myCustomObject__c" required="true" /> 
  <apex:attribute name="lname" description="ln" type="myCustomObject__c" required="true" /> 

    <!-- more fields -->
    <apex:inputText value="{!fname.f_name__c}" id="fname"> </apex:inputText>
    <apex:inputText value="{!mname.m_name__c}" id="mname"> </apex:inputText>
    <apex:inputText value="{!lname.l_name__c}" id="lname"> </apex:inputText>


VF Page:

<apex:page controller="NameInputTextPageController" >


  <c:NameInputTextComponent id="vfcom" 
      fname="{!firstname}" mname="{!middlename}" lname="{!lastname}"

    <apex:commandButton action="{!saveme}" value="Save Data" />


VF Page Controller:

public with sharing class NameInputTextPageController {
    public NameInputTextPageController() {}

    public PageReference saveme() {
        return null;
  • Your controller is doesn't have the properties defined you are trying to reference...
    – Adrian Larson
    Mar 2, 2016 at 21:04
  • correct! that's the part i'm trying to know how to handle it
    – Nick
    Mar 2, 2016 at 21:05
  • saveMe isn't doing any DML
    – cropredy
    Mar 2, 2016 at 21:17
  • @crop1645: i have just created action and off course needs to address how to grab the user entry data and save it and yes eventually it will be doing DML operation. sorry for the confusion
    – Nick
    Mar 2, 2016 at 21:19
  • 1
    so firstName, middleName, and lastName are three instances of myCustomObject__c ? A separate object for each portion of someone's name?
    – cropredy
    Mar 2, 2016 at 21:21

1 Answer 1


A couple things:

  • Add allowDml="true" to your <apex:component> tag.
  • You only need to pass one instance of your record, not three.
  • You can pass an ApexPage.Action and invoke that from your component.

Your markup could probably be simplified to something like:

<apex:page standardController="MyObject__c">
        <apex:commandButton value="Save" action="{!save}" />
        <c:nameInputs record="MyObject__c" />

Then your component:

<apex:component allowDml="true">
    <apex:attribute name="record" type="MyObject__c" required="true"
        description="SObject record to edit" />\

        <apex:inputField value="{!record.f_name__c}" id="fname" />
        <apex:inputField value="{!record.m_name__c}" id="mname" />
        <apex:inputField value="{!record.l_name__c}" id="lname" />
  • 1+ make sense how you simplified the page but confused where does the saving take place? i mean controller?
    – Nick
    Mar 2, 2016 at 21:12
  • @AbuHamzah Just add it to a commandButton as you would with the save action normally. Updated my markup to demonstrate.
    – Adrian Larson
    Mar 2, 2016 at 21:14
  • but if you look at my markup the save button is on the VF page not on the VF component.
    – Nick
    Mar 2, 2016 at 21:16
  • @AbuHamzah Just use the save action on your page instead then. This structure will bind the values back.
    – Adrian Larson
    Mar 2, 2016 at 21:27
  • I'm not getting the value so I have allowDml="true in the component and in the VF page I have public PageReference save() { system.debug(MyObject__c.f_name__c) } i get empty value in the debug
    – Nick
    Mar 2, 2016 at 22:54

You must log in to answer this question.

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