function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Simha YadavSimha Yadav 

i want to change row of color in visualforce page.

Please Help anybody.... i want to change row of color in visualforce page when the Email Status column shows Email has sent then it should change that row color to light green if it shows as not sent then it should change the color to red,How do i do this?
But i did something but its not working below is my code.

<apex:page standardController="Account" extensions="WrapperDemoClass" showHeader="false" sidebar="false">
  <script type="text/javascript">
        function selectAllCheckboxes(obj,receivedInputID){
            var inputCheckBox = document.getElementsByTagName("input");                  
            for(var i=0; i<inputCheckBox.length; i++){          
                if(inputCheckBox[i].id.indexOf(receivedInputID)!=-1){                                     
                    inputCheckBox[i].checked = obj.checked;
                }
            }
        }
    </script>
    
    <style>
    .EmailnotSentClass {
        background-color: #F7DDDD;
    }
    .EmailSentClass {
        background-color: #66FF99;
    }
    </style>

  <apex:form >
    <apex:pageBlock title=" Account Invoice">
    <br/>
    <br/>
    <apex:pageMessages />
     <apex:commandButton value="Send Email" action="{!sendEmail}" reRender="pgBlckId" status="actStatusId" />
        &nbsp;
       <apex:actionStatus id="actStatusId" >
       <apex:facet name="start" >
       <apex:image url="{!$Resource.Image}" />
       </apex:facet>
       </apex:actionStatus>
     <br/>
     <br/>
     <br/>
       <apex:pageblockTable value="{!wrapperObj}" var="Rec" title="All Accounts">
         <apex:column styleClass="{!IF(colorcheck == 'green','EmailnotSentClass','EmailSentClass')}">      
         <apex:facet name="header">
         <apex:inputCheckbox onclick="selectAllCheckboxes(this,'inputId')"/>
         </apex:facet>
         <apex:inputCheckbox value="{!Rec.checkBox}" id="inputId" />
         </apex:column>
         <apex:column value="{!Rec.accObj.name}" styleClass="{!IF(colorcheck == 'green','EmailnotSentClass','EmailSentClass')}"/>
        
         <apex:column value="{!Rec.accObj.phone}" styleClass="{!IF(colorcheck == 'green','EmailnotSentClass','EmailSentClass')}"/>
         
         <apex:column value="{!Rec.accObj.Email__c}" styleClass="{!IF(colorcheck == 'green','EmailnotSentClass','EmailSentClass')}"/>
         
         <apex:column headerValue="Created Date" styleClass="{!IF(colorcheck == 'green','EmailnotSentClass','EmailSentClass')}">
             <apex:outputText value="{0,date,dd/MM/yyyy}">
                 <apex:param value="{!Rec.accObj.createddate}"/>
             </apex:outputtext>
         </apex:column>
         <apex:column value="{!Rec.accObj.Type}" styleClass="{!IF(colorcheck == 'green','EmailnotSentClass','EmailSentClass')}"/>
         <apex:column value="{!Rec.accObj.Email_Status__c }" id="pgBlckId" styleClass="{!IF(colorcheck == 'green','EmailnotSentClass','EmailSentClass')}"/>
         
      </apex:pageblockTable> 
    </apex:pageblock>
    
  </apex:form>
</apex:page>



public with sharing class WrapperDemoClass {
    Public List<WrapperClassEx> WrapperList{get;set;}
    public List<Account> accList {get;set;}
    public boolean checked {get;set;}
    public string  colorcheck {get;set;}
    public WrapperDemoClass(ApexPages.StandardController controller) {
       colorcheck = '';
    }
   
   Public List<WrapperClassEx> getwrapperObj(){
      accList = [Select id,name,phone,Email__c,createddate,type,Email_Status__c from account];
      WrapperList = New List<WrapperClassEx>();
      for(Account acc: accList){
        WrapperList.add(New WrapperClassEx(acc,false)); 
      }
      return WrapperList;
   } 
   
   public void sendEmail(){
       checked = false;
     List<Messaging.SingleEmailMessage> lstEmailId=new List<Messaging.SingleEmailMessage>();
     
         PageReference pdf = Page.newreq;
        // add parent id to the parameters for standardcontroller
        //pdf.getParameters().put('id',accountId);
    
        // the contents of the attachment from the pdf
        Blob body;
    
        try {
    
          // returns the output of the page as a PDF
          body = pdf.getContent();
    
        // need to pass unit test -- current bug  
        } catch (VisualforceException e) {
          body = Blob.valueOf('Some Text');
        }
   
     for(WrapperClassEx w : WrapperList){
        for(Account a : accList){
            if(w.accObj.id == a.id){
                system.debug('w.checkBox :'+w.checkBox);
                if(w.checkBox == true){
                    /*if(w.accObj.Email__c == null){
                        w.ErrorMessage = 'Email has not sent! Please check with your Admin.';
                        system.debug('errormsg:'+w.ErrorMessage);
                        
                    }continue;*/
                    
                    Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();
                    attach.setContentType('application/pdf');
                    attach.setFileName('Invoice.pdf');
                    attach.setInline(false);
                    attach.Body = body;
                    
                    Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                    mail.setToAddresses(new String[] {w.accObj.Email__c});
                    //mail.setReplyTo('sumit.shukla@magicsw.com');
                    mail.setplainTextBody('Hello');  
                    mail.setSenderDisplayName('Your Company Name');      
                    mail.setSubject('Test Email From Force.com Sites');  
                    //mail.setTemplateId('00X90000001GCde');                                      
                    mail.setFileAttachments(new Messaging.EmailFileAttachment[] { attach });      
                             
                    //lstEmailId.add(mail);
                    try{
                        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });  
                        checked = true;
                        a.Email_Status__c  = 'Email has sent!';
                        colorcheck = 'green';
                        system.debug('errormsg:'+w.ErrorMessage);
                    }catch(exception e){ 
                        a.Email_Status__c  = 'Email has not sent! Please check with your Admin.';
                        colorcheck = 'red';
                        system.debug('errormsg:'+w.ErrorMessage);
                    }
                    system.debug('lstEmailId :'+lstEmailId);                        
                }
            }
        }
      }
      upsert accList;
      
    }     
   

  
   Public Class WrapperClassEx{
     Public Account accObj{get;set;}
     Public Boolean checkBox{get;set;}
     public String ErrorMessage{get;set;}
     Public WrapperClassEx(Account accRec, boolean SelectBox){
        accObj = accRec;
        checkBox = SelectBox;
     }
   }
   }
Gyanender SinghGyanender Singh
Hi simha,

Can you send the image of the Statice Resource Image because want to implement this code and try to solve your problem.

Thanks
Gyani