Salesforce: Dynamically Assign the style in the Visualforce page

//CSS Style
 .red {
            background-color: red;
        }
        .green {
            background-color: green;
        }
        .yellow {
            background-color: green;
        }
     
//VF Page code
    <apex:pageBlockTable value="{!recordList}" var="record">
        <apex:column styleClass="{!record.colorCode}" headerValue="Created Date">
           {!record.createdDate}
        </apex:column>
    </apex:pageBlockTable>
     

//Apex Class to get the values
   public List<accountRecord> recordList {get; set;}
public void getAccount() { recordList = new List<accountRecord>(); for(Account record:[SELECT CreatedDate FROM Account]) { String colorCode = (record.CreatedDate>System.Now().addDays(-3))?'green':(record.CreatedDate>System.Now().addDays(-5))?'yellow':'red'; recordList.add(new accountRecord(record.CreatedDate,colorCode)); } } public class accountRecord { public DateTime createdDate { get; set; } public String colorCode { get; set; } public accountRecord(DateTime submittedDate, String colorCode) { this.submittedDate = submittedDate; this.colorCode = colorCode; } }
       


Comments

Popular posts from this blog

Transaction Security Policy In Salesforce

Salesforce Data Cloud

Add/Remove Content in the VF Page using JS