I'm trying to assign Id to my inputField dynamically, those input fields are coming from field sets. These Ids needs to be assigned to those fields which are required in database.

On giving Id dynamically I'm getting Literal value is required for attribute id in error.

Based on those ids I need to perform some check in javascript, before saving the record.

<apex:outputPanel id="mySalesforceFields">
  <apex:repeat value="{!fieldSetMemberList}" var="field">
    <apex:inputField value="{!sObject[field]}" required="{!if((field.dbRequired || field.required), true,false)}" 
    id="{!if((field.dbRequired || field.required), field.label,'')}" />

  • Why do you think you need it? You may wish to read up on what an XY Problem is and describe what you are trying to achieve at a higher level.
    – Adrian Larson
    Mar 13, 2018 at 16:59

1 Answer 1


You can't dynamically assign the Visualforce id attribute. You can, however, assign data- attributes or pass through html- attributes. See, for example, Setting Custom HTML Attributes on Visualforce Components . Make sure you use a unique value such as the field's API Name rather than its Label if you decide to pass through an html-id.

Probably better to use data- attributes. You can still select on them.

<apex:inputField ... html-data-id="{!field}"
    html-data-required="{!OR(field.required, field.dbRequired)}" />

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.