I have a custom object Response__c as shown below.

enter image description here

xx,yy,zz are different field values for the three records.

Please note that not all fields are populated for all the three records.

A single apex:inputfield is to be shown in the VF Page whose "value" property will be determined at runtime

I followed an earlier post's advice

VF component dynamic inputField

and refactored my code as below

Component markup

<apex:component controller="DynamicApexController" >
    <apex:attribute name="inputObject" type="sObject" description="Object Name"/>
    <apex:attribute name="inputFieldName" type="String" description="Field Name"/>
    <apex:inputField value="{!r[inputFieldName]}"/>

Component controller

public with sharing class DynamicApexController {

public Response__c r {get;set;}
public Response__c getr()

Response__c newr = new Response__c();
return newr;



Visualforce Page

<!-- Page: -->

<apex:page >
<apex:form >

    <c:myComponent1 myValue="My composents value" borderColor="green" /> 
    <c:dynamicinput inputFieldName="Field1__c"  id="first" rendered="true" />

But I am getting the following error when navigating to the VF Page. Attached is the error screenshot below.

Can someone let me know what is wrong ?

Error Screenshot

enter image description here


1 Answer 1


Please have a look at this - VF component dynamic inputField.

I think you should replace r with attribute inputobject and pass the inputobject parameter from VF to even make sobject dynamic.

Thanks, Abhishek

You must log in to answer this question.

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