I have in controller inner class with sobject and custom id. In visualforce page I have apex repeat over this inner classes. In repeat block are two fields (picklists) which are dependent. Everything works fine, but I need to add my custom Id as styleClass to these fields. For example:

<apex:repeat value="{!lst}" var="s"> 
<apex:inputfield value="{!s.Oli.field1__c}" styleclass="{!s.customid}" />
<apex:inputfield value="{!s.Oli.field2__c}" styleclass="{!s.customid}" />

my class

public myController {
 public list<OliRow> lst {get;set;}
 public class OliRow{
   public OpportunityLineItem Oli {get; set;}
   public customId {get;set;}
   public OliRow(OpportunityLineItem thisOli){
     oli = thisOli;
    //logic for populat customId

   public myController(){
      lst = new list<OliRow>();
      for(OpportunitylineItem objOli : [SELECT id,...FROM OpportunitylineItem WHERE ..]){
         lst.add(new OliRow(objOli));
      //other logic

In this scenario my picklist do not have these styles. I tried htm5 params:

<apex:inputfield value="{!s.Oli.field1__c}" html-data-id="{!s.customid}" />

but it not works too.

I need this customid id for javascripts.

please Do not care of this apex code, which works perfect. CustomId is random string with some logic. If I put it there it will be only confused. I try to eplain it in other way

<apex:repeat value="{!lst}" var="s"> 
    <apex:inputfield value="{!s.Oli.field1__c}" styleclass="{!s.customid}" /> <!-- controlling field-->
    <apex:inputfield value="{!s.Oli.field2__c}" styleclass="{!s.customid}" />  <!-- depended field-->
    <apex:inputfield value="{!s.Oli.field3__c}" styleclass="{!s.customid}" /> <!-- not depended field -->

HTML which I get in salesforce for one line is (in short form)

<select id="salesforceGeneratedId"><options for field1 >...</select>
<select id="salesforceGeneratedId2"><options for field2 >...</select>
<select id="salesforceGeneratedId3" class="mycustomid"><optios for field3>...</select>

My problem is why I do not have class="mycustomid" for first 2 select (picklist)

I put quotes (at first it did some wrong formats for code here)
I put here sample class
highfive: I put how I populate lst, but it do not affect on my problem, as I said everything works fine, insted of add customid as styleClass. When I look at the HTML of page, do bot have my attributes, only salesforce id and name (I can use it for my purpouse)
Add new example

  • Please include your inner class in the question; s.field1__c suggests s is a custom object but s.customid suggests s is an Apex class.
    – Keith C
    Apr 8, 2014 at 12:10
  • 2
    Are you missing your single quote marks value={!s.field1__c} and everywhere as it appears in your post?
    – highfive
    Apr 8, 2014 at 12:11
  • Please add the code to show how your are populating the lst in your controller
    – highfive
    Apr 8, 2014 at 12:58
  • In your edited post also we can't see where you are populating the field customId in your inner class. If you are not initializing it yes of course you are not getting any value for that at the UI end
    – highfive
    Apr 8, 2014 at 13:17

2 Answers 2


The styleClass attribute (and others) does not work for <apex:inputField> when it is a dependent picklist. I would just wrap it with an <apex:outputPanel> and set the styleClass there. Then in javascript detect when it's a dependent picklist and get the child select element of the <apex:outputPanel>.


In order to help you out, we need an accurate representation of your code from the get go. That being said, the following line is commented out: //logic for populat customId. Since this is commented out, customId is never set, and as a result, you will not have your style attribute populated in visualforce.

If you're just commenting it out for the sake of the question, please put it in so we can help further.

You must log in to answer this question.

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