Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to conditionally render an apex:inputField only if the field exists on the running org?

I tried the following syntax but always ran into errors:

<apex:inputField value="{!CustomObject__c['optionalField__c']}" />
<apex:inputField value="{!CustomObject__c['optionalField']}"  
   rendered="{!NOT(ISNULL($ObjectType.CustomObject__c.fields['optionalField__c']))}" />
share|improve this question
as far as I know, you can't, inputfields are hard-bound to an sobject field which must exist in the org, else you will fail on saving. You could potentially make workarounds with normal HTML, and javascript/css, combined with extension variables, but this is quite a hassle. – pjcarly Jan 31 '13 at 9:47
up vote 5 down vote accepted

I didn't find any solution for this but I think as per your requirement you should use "FieldSets" and use that FieldSet to render fields on you visualforce page.

Here you can find FieldSet information.

I am suggesting this to you because i am using this and rendering the input fields based on some condition and it is working fine.

share|improve this answer
How come that this doesn't work for the RecordType field? – Robert Sösemann Feb 2 '13 at 2:12

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.