Changing an individual field colour in Apex

Problem


You have a field that you want to change colour.
There are a few pages talking about how to do this on interactive reports, but this is just a standalone field.

Solution

Here are my fields


Go to the region holding these fields and change the type to "PL/SQL Dynamic Content"



PL/SQL Code

htp.p('<style>');
htp.p('#P12_2 {background-color: #F8FACC;}');
htp.p('</style>');


This simple code will change the background colour of field "P12_2" to a light yellow colour (#F8FACC)

Now we can extent this logic

declare
begin
htp.p('<style>');
htp.p('#P12_'||trunc(to_char(sysdate,'MM'))||' {background-color: #F8FACC;}');
htp.p('</style>');
end;

Now with the same code, I am highlighting field 1..12 depending on what the current month is.


Further Tip:
If running your app in Chrome, press F12, you get a modal window which shows you all the code that went behind displaying your page.


To zoom in on the code used for displaying your field, right click on your field in your app and lick "Inspect".
It now tells you specifically the code used for displaying this field, and you can directly edit (for example_ the background colour to see what it would look like.



Acknowledgement

Thanks to Theo: https://www.linkedin.com/in/papadakistheo

Comments