{"id":268,"date":"2016-05-17T10:00:00","date_gmt":"2016-05-17T05:00:00","guid":{"rendered":"https:\/\/learnsf.wordpress.com\/?p=268"},"modified":"2023-12-30T17:11:48","modified_gmt":"2023-12-30T23:11:48","slug":"using-colors-in-reports-and-page-layouts","status":"publish","type":"post","link":"https:\/\/blog.felineflock.com\/index.php\/2016\/05\/17\/using-colors-in-reports-and-page-layouts\/","title":{"rendered":"Unlock the Power of Color in Your Reports and Page Layouts"},"content":{"rendered":"<p>Other than using Rich Text fields,\u00a0there are rigid\u00a0limits in regards to how fields\u00a0appear on a page layout or report.<br \/>\nIn the Account report below, you can see a text field that appears in different colors depending on the industry of the account. This article shows one way\u00a0to obtain that functionality.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-271\" src=\"http:\/\/blog.felineflock.com\/wp-content\/uploads\/2016\/05\/reportcoloredtext.png\" alt=\"ReportColoredText\" width=\"1722\" height=\"998\" srcset=\"https:\/\/blog.felineflock.com\/wp-content\/uploads\/2016\/05\/reportcoloredtext.png 1722w, https:\/\/blog.felineflock.com\/wp-content\/uploads\/2016\/05\/reportcoloredtext-300x174.png 300w, https:\/\/blog.felineflock.com\/wp-content\/uploads\/2016\/05\/reportcoloredtext-1024x593.png 1024w, https:\/\/blog.felineflock.com\/wp-content\/uploads\/2016\/05\/reportcoloredtext-768x445.png 768w, https:\/\/blog.felineflock.com\/wp-content\/uploads\/2016\/05\/reportcoloredtext-1536x890.png 1536w\" sizes=\"auto, (max-width: 1722px) 100vw, 1722px\" \/><\/p>\n<p>Below is the formula used to display the colored text:<\/p>\n<blockquote><p>IMAGE( &#8220;\/apex\/TextToImage?color=&#8221;<br \/>\n+<br \/>\nIF( CONTAINS( &#8216;Energy|Construction|Transportation|Shipping|Utilities|Manufacturing|Agriculture&#8217;, TEXT( Industry ) ), &#8216;red&#8217;, &#8216;green&#8217; )<br \/>\n+ &#8220;&amp;text=&#8221;<br \/>\n+ SUBSTITUTE( Name, &#8220;&amp;&#8221;, &#8220;%26amp;&#8221; ) + &#8221; (&#8221;<br \/>\n+ IF( CONTAINS( &#8216;Energy|Construction|Transportation|Shipping|Utilities|Manufacturing|Agriculture&#8217;, TEXT( Industry ) ), &#8216;Basic&#8217;, &#8216;Service&#8217; ) + &#8221; Industry)&#8221;, &#8220;Test&#8221; )<\/p><\/blockquote>\n<p>Notice how it starts with an IMAGE() function with a concatenation of:<\/p>\n<ol>\n<li>a link to a VisualForce page<\/li>\n<li>a parameter &#8220;color&#8221; followed by&#8230;<\/li>\n<li>&#8230;an IF() function that determines whether the text should appear in red or green<\/li>\n<li>a parameter &#8220;text&#8221; followed by&#8230;<\/li>\n<li>&#8230;a SUBSTITUTE() function that replaces any &#8220;&amp;&#8221; character in the Account Name with an\u00a0equivalent escape code<\/li>\n<li>another IF() function that determines whether to append the words &#8220;(Basic Industry)&#8221; or &#8220;(Service Industry)&#8221; depending on the picklist value of the Account Industry<\/li>\n<\/ol>\n<p>That is right, this formula transforms a text field into an image using a VisualForce page! How is that possible?<\/p>\n<p>Here is the page markup for TextToImage:<\/p>\n<blockquote>\n<pre class=\"codeBlock\">&lt;apex:page sidebar=\"false\" showHeader=\"false\"\n applyHtmlTag=\"false\" applyBodyTag=\"false\" \n standardStylesheets=\"false\" \n ContentType=\"image\/svg+xml\" &gt;\n    &lt;apex:variable var=\"textWidth\" \n         value=\"{! LEN( $CurrentPage.parameters.Text ) * 10 }\"\/&gt;\n    &lt;apex:variable var=\"textColor\" \n         value=\"{!IF( $CurrentPage.parameters.Color = null, \n                  'red', $CurrentPage.parameters.Color )}\" \/&gt;\n\n    &lt;svg id=\"layer_1\" \n        xmlns=\"http:\/\/www.w3.org\/2000\/svg\" \n        xmlns:xlink=\"http:\/\/www.w3.org\/1999\/xlink\" \n        height=\"20\" width=\"{! textWidth }\"&gt;\n      &lt;text x=\"0\" y=\"15\" font-family=\"Verdana\" \n          font-weight=\"bold\" fill=\"{! textColor }\"&gt;\n          {! $CurrentPage.parameters.Text }\n      &lt;\/text&gt;\n    &lt;\/svg&gt;\n&lt;\/apex:page&gt;<\/pre>\n<\/blockquote>\n<p>In this page there are 3 unusual things:<\/p>\n<ol>\n<li>no controller, no header, no sidebar, no style sheet<\/li>\n<li>the ContentType is set to image\/svg+xml<\/li>\n<li>the SVG tag containing a TEXT tag<\/li>\n<\/ol>\n<p>The SVG image format &#8211; <a href=\"https:\/\/en.wikipedia.org\/wiki\/Scalable_Vector_Graphics\" target=\"_blank\" rel=\"noopener\">Scalable Vector Graphics<\/a> &#8211; is relatively less known standard but it is very versatile and compatible with virtually all browsers. It allows us to define an image using plain XML.<\/p>\n<p>In order to generate an image, this VisualForce page uses the parameters Text and Color. Color can be any CSS color code such as #FF00FF, #00A0C0, etc or a CSS color name such as red, green, darkblue, etc.<br \/>\nAn URL like below would make the text &#8220;This is a test.&#8221; appear in cyan:<\/p>\n<p style=\"padding-left:30px;\">\/apex\/TextToImage?color=cyan&amp;text=This+is+a+test.<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone  wp-image-337\" src=\"http:\/\/blog.felineflock.com\/wp-content\/uploads\/2016\/05\/screen-shot-2016-05-17-at-12-59-35-am.png\" alt=\"Screen Shot 2016-05-17 at 12.59.35 AM\" width=\"133\" height=\"22\" \/><\/p>\n<p>This way of manipulating text with SVG opens the door to a few ideas and allows interesting features that will be explored in the <a href=\"https:\/\/learnsf.wordpress.com\/2016\/05\/18\/formatting-long-text-fields-in-reports-and-page-layouts\/\">next article<\/a>s&#8230; (hint: \u00a0check out the bar codes in the first image!)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Other than using Rich Text fields,\u00a0there are rigid\u00a0limits in regards to how fields\u00a0appear on a page layout or report. In the Account report below, you can see a text field that appears in different colors depending on the industry of the account. This article shows one way\u00a0to obtain that functionality. Below is the formula used [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":271,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[11],"tags":[],"class_list":["post-268","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-formula"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/blog.felineflock.com\/index.php\/wp-json\/wp\/v2\/posts\/268","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.felineflock.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.felineflock.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.felineflock.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.felineflock.com\/index.php\/wp-json\/wp\/v2\/comments?post=268"}],"version-history":[{"count":2,"href":"https:\/\/blog.felineflock.com\/index.php\/wp-json\/wp\/v2\/posts\/268\/revisions"}],"predecessor-version":[{"id":555,"href":"https:\/\/blog.felineflock.com\/index.php\/wp-json\/wp\/v2\/posts\/268\/revisions\/555"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.felineflock.com\/index.php\/wp-json\/wp\/v2\/media\/271"}],"wp:attachment":[{"href":"https:\/\/blog.felineflock.com\/index.php\/wp-json\/wp\/v2\/media?parent=268"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.felineflock.com\/index.php\/wp-json\/wp\/v2\/categories?post=268"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.felineflock.com\/index.php\/wp-json\/wp\/v2\/tags?post=268"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}