Pages

Sunday, July 7, 2013

Salesforce image formula field

What is the most easy way to get user attention in a Salesforce page? One of the best option is to use image. You can build Visualforce page (and with Apex code) to display images in Salesforce page. But, hold on, Visualforce is not the only way to display image. You can use IMAGE() in a formula field, this is much more easier and faster if possible.

See below use cases:

1. Show customer support status
If a customer purchase support product and still active, show active sign, if no longer active, show expired sign and if not purchase any support, show cross sign.

For this case, you need to upload 3 images into a document. I'll not discuss on how to upload images to a document folder. But, you can look from think link, please note the max size for document only 5 MB.
After all images uploaded to a folder in document, follow this steps:
  • Create a New formula field
  • Name the field “Support Status”
  • Choose Text as the formula field type
  • Copy and paste following formula 
IF (NOT ISNULL(Support_Expiration_Date__c), IF (Support_Expiration_Date__c > Today(), IMAGE("/servlet/servlet.ImageServer?id=01550000000eCt0&oid=00D300000000SHq","Active"), IMAGE("/servlet/servlet.ImageServer?id=01550000000OD0h&oid=00D300000000SHq","Expired")), IMAGE("/servlet/servlet.ImageServer?id=01550000000dXsc&oid=00D300000000SHq","No Support"))

Basically, parameters for id = Image Id and oid = Organization Id, you can get the URL from document page. At the image field, right click and select "Open image in new tab" (for Google Chrome).
To use servlet.ImageServer make sure Externally Available Image is enabled, otherwise change the format to
/servlet/servlet.FileDownload?file=01550000000eiu6


2. Show customer category depend on opportunity Closed Won amount
  • Create Roll-Up Summary field in Account
  • Name the field "Closed Won Amount"
  • Select "Opportunities" in object to summarized, 
  • Roll-Up Type = Amount; Field to Aggregate = Amount; Filter Criteria only record Won equals to True. Done for Roll-Up Summary field
  • Create a New Formula field in Account
  • Name the field “Customer Category”
  • Choose Text as the formula field type
  • Copy and paste following formula 
IF ( Closed_Won_amount__c > 0, IMAGE("/servlet/servlet.FileDownload?file=01550000000eiu6", "money", 18,18), NULL)
+ " " +
IF ( Closed_Won_amount__c > 10000, IMAGE("/servlet/servlet.FileDownload?file=01550000000eiu6", "money", 18,18), NULL)
+ " " +
IF ( Closed_Won_amount__c > 25000, IMAGE("/servlet/servlet.FileDownload?file=01550000000eiu6", "money", 18,18), NULL)
+ " " +
IF ( Closed_Won_amount__c > 50000, IMAGE("/servlet/servlet.FileDownload?file=01550000000eiu6", "money", 18,18), NULL)
+ " " +
IF ( Closed_Won_amount__c > 100000, IMAGE("/servlet/servlet.FileDownload?file=01550000000eiu6", "money", 18,18), NULL)


Here is the final layout in Account page layout: