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
neshnesh 

Highlight in RED if below 75%--conditionally highlight a custom field in VF

How to highlight a custom field based on condion( Highlight in RED if below 75% ).

custom field name:Total Grade.(data type :percentage )

my vf page code:

<apex:pageblockSection title="Total Grade">

<apex:outputField value="{!newapp.Total_grade_1__c}" styleclass="{!if((newapp.Total_grade_1__c<75), 'color:red', '')}" /

</apex:pageblockSection>

above code doesnt work. my custom field data type is percentage...Please help me.

Best Answer chosen by Admin (Salesforce Developers) 
GlynAGlynA

Nesh,

 

I'm sorry that you haven't gotten the code to work yet; but I'm volunteering to help you and I would appreciate it if you didn't yell at me with ALL CAPS.  I have created a complete test - VisualForce page and controller - that shows how to accomplish what you are trying to do.

 

The page:

<apex:page controller="OpportunityList">

<apex:pageBlock >
<apex:pageBlockTable value="{!list_Opportunities}" var="opp">
    <apex:column value="{!opp.Name}"/>
    <apex:column value="{!opp.Probability}" style="{!if(opp.Probability<75,'color:red','')}"/>
</apex:pageBlockTable>
</apex:pageBlock>

</apex:page>

The controller:

public class OpportunityList
{
    public List<Opportunity> list_Opportunities
    {
        get
        {
            if ( list_Opportunities == null )
            {
                list_Opportunities = [SELECT Id, Name, Probability FROM Opportunity LIMIT 100];
            }
            return list_Opportunities;
        }
        private set;
    }
}

The output:

Opportunity List Output

 

This example works.  It provides the solution to your question.  Good luck with your project.

 

-Glyn

All Answers

GlynAGlynA

Nesh,

 

Try this:

 

<apex:outputField value="{!newapp.Total_grade_1__c}" style="{!if((newapp.Total_grade_1__c<75), 'color:red', '')}" />

 And if that doesn't work, try this:

 

<apex:outputField value="{!newapp.Total_grade_1__c}" rendered="{!newapp.Total_grade_1__c>=75}" />
<apex:outputField value="{!newapp.Total_grade_1__c}" rendered="{!newapp.Total_grade_1__c<75}" style="color:red" />

 

If this helps, please mark it as a solution, and give kudos (click on the star) if you think I deserve them. Thanks!

 

-Glyn Anderson
Certified Salesforce Developer | Certified Salesforce Administrator

neshnesh
<apex:outputField value="{!newapp.Total_grade_1__c}" style="{!if((newapp.Total_grade_1__c<75), 'color:red', '')}" />- ABOVE CODE IS NOT WORK.MY CONDTION IS Highlight in RED if below 75% --Otherwise display normal. my custom field data type is percentage.
GlynAGlynA

Did you try the second version?  It should work.

 

Using style="color:red" will cause the text to be printed in red color.  Do you want the background filled with red?  That will be a different style...

neshnesh
second conditionalso doesnt work. my customfield name TOTAL GRADE. DATA TYPE==PERCENTAGE--IS ANY PROBLEM WITH DATATYPE . BECAUSE WE PUT <75 ,>=75..otherwise give your idea for this task.
GlynAGlynA

Nesh,

 

I'm sorry that you haven't gotten the code to work yet; but I'm volunteering to help you and I would appreciate it if you didn't yell at me with ALL CAPS.  I have created a complete test - VisualForce page and controller - that shows how to accomplish what you are trying to do.

 

The page:

<apex:page controller="OpportunityList">

<apex:pageBlock >
<apex:pageBlockTable value="{!list_Opportunities}" var="opp">
    <apex:column value="{!opp.Name}"/>
    <apex:column value="{!opp.Probability}" style="{!if(opp.Probability<75,'color:red','')}"/>
</apex:pageBlockTable>
</apex:pageBlock>

</apex:page>

The controller:

public class OpportunityList
{
    public List<Opportunity> list_Opportunities
    {
        get
        {
            if ( list_Opportunities == null )
            {
                list_Opportunities = [SELECT Id, Name, Probability FROM Opportunity LIMIT 100];
            }
            return list_Opportunities;
        }
        private set;
    }
}

The output:

Opportunity List Output

 

This example works.  It provides the solution to your question.  Good luck with your project.

 

-Glyn

This was selected as the best answer
neshnesh
Thanks very much For share ur knowledge GlynA .Now its worked.
GlynAGlynA

I'm glad it's working for you now.  Please mark my post as the solution so that others may benefit.  Thank you!

 

-Glyn

neshnesh

How to call  apex class from List View Custom Button  ..my inside apex class code is here- how to use it...Please help me

INSIDE CLASS:
List <training__c> t1 = new list <training__c>();
       list <training_survey__c> ts2 = new list<training_survey__c>();
       t1 = [ select day1surveyflag__c, day3surveyflag__c, day5surveyflag__c from training__c where day1surveyflag__c = true or day3surveyflag__c = true or day5surveyflag__c = true ];
       for(training__c tx : t1)
          {
             training_survey__c ts = new training_survey__c();
             ts.training__C = tx.id;
             if(tx.day1surveyflag__c == true )
               {
                 ts.Survey_Type__c = 'Day1';
               }else
             if(tx.day3surveyflag__c == true )
               {
                 ts.Survey_Type__c = 'Day3';
               }else
             if(tx.day5surveyflag__c == true )
               {
                 ts.Survey_Type__c = 'Day5';
               }else
               {
                 ts.Survey_Type__c = 'Dropped';
               } 
             RecordType r = [Select id from Recordtype where sobjecttype = 'training_survey__c' and name= :ts.Survey_Type__c];
             ts.RecordTypeid = r.id;
             ts2.add(ts); 
          } 
        if(ts2 != null )
         {
           insert ts2;  
         }  
GlynAGlynA

Nesh,

 

You should make this a new thread - post it as a new question.  I have an answer for you, but I'd like to make it a new answer to a new question.  Thanks!

 

-Glyn