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
Norm GilbertNorm Gilbert 

Display an Image with CASE() in Trailhead

I am stuck on the Challenge to Create a formula field that returns an image to indicate data quality. It's in the Text Formulas module of Advanced Formulas badge.

No matter what I try, I can't pass the Syntax checker. I am required to display a certain number of stars based on Data Quality calculated in another formula. And include alternate text. (By the way, is there any way to trace formulas, so I could see the number being returned by the data quality formula?)

Herer's my formula . . . 

IMAGE
(CASE(Lead_Quality_Helper__c ,
5, ("/img/samples/stars_500.gif", "5 Stars",)
4, ("/img/samples/stars_400.gif", "4 Stars",)
3, ("/img/samples/stars_300.gif", "3 Stars",)
2, ("/img/samples/stars_200.gif", "2 Stars",)
1, ("/img/samples/stars_100.gif", "1 Stars",)
0, ("/img/samples/stars_000.gif", "0 Stars",)
"Unknown"))

IMAGE can take two parameters. The URL and the ALTERNATE TEXT. So I put both parameters surrounded by (.....). The Syntax checker says I am missing a parenthesis between the URL and the Alternate Text. But inserting one there results in an error that CASE is expecting a number, not text.

What am I doing wrong here?
NagendraNagendra (Salesforce Developers) 
Hi Gilbert,

A helper formula is just a formula field that is referenced by another formula field.  For instance, I create a Formula_A__c field that references Formula_B__c.

For an image formula, you'll create a formula field that's actually a Text type, and then in the formula editor, you'll use the IMAGE() formula to produce an image.  The image formula is actually discussed in the description or scenario of the same Trailhead challenge you're working on. 

I completed this challenge as below:
Lead Quality Helper:
IF(ISBLANK(Email) , 0, 1) + IF(ISBLANK(Phone) , 0, 1) + IF(ISBLANK(Company) , 0, 1) + IF(ISBLANK(Title) , 0, 1) + IF( ISPICKVAL(Industry , ""), 0, 1)

Lead Quality:
IMAGE( 
CASE( Lead_Quality_Helper__c , 
1, "/img/samples/stars_100.gif ", 
2, "/img/samples/stars_200.gif", 
3, "/img/samples/stars_300.gif", 
4, "/img/samples/stars_400.gif", 
5, "/img/samples/stars_500.gif", 
"/img/samples/stars_000.gif"), 
"0 stars")
Hope this helps.

Please mark this as solved if it's resolved so that it gets removed from the unanswered queue which results in helping others who are encountering a similar issue.

Thanks,
Nagendra


 
Norm GilbertNorm Gilbert
Where is the alternate text in your image formula? I don't see it. Norm Gilbert Tour Guide, City Sightseeing SF M 415-465-4220 | F 415-423-3355 | fogcitynative@gmail.com | www.city-sightseeing.us | Skype: fogcitynative | 355 Serrano Dr. #12A, San Francisco, CA 94132 "The best way to avoid a cesarean is to stay out of the hospital." - Brooke Sanders Purves
Aaron Haag 7Aaron Haag 7
The above snippet probably works because it tests for 0 stars and that formula passes 0 stars as  the alt text at the end. To do it completely correctly, you need a second case function. The first Case function passes the url to the Image function and the second case function will pass the alt text. See below:
IMAGE( 
   CASE( Lead_Quality_Helper__c , 
      1, "/img/samples/stars_100.gif ", 
      2, "/img/samples/stars_200.gif", 
      3, "/img/samples/stars_300.gif", 
      4, "/img/samples/stars_400.gif", 
      5, "/img/samples/stars_500.gif", 
      "/img/samples/stars_000.gif"),
  CASE( Lead_Quality_Helper__c , 
      1, "1 star", 
      2, "2 stars", 
      3, "3 stars", 
      4, "4 stars", 
      5, "5 stars", 
      "0 stars"))

 
Rahul Kumar DeyRahul Kumar Dey
@Norm Gilbert

IMAGE( CASE( Lead_Quality_Helper__c , 1, "/img/samples/stars_100.gif ", 2, "/img/samples/stars_200.gif", 3, "/img/samples/stars_300.gif", 4, "/img/samples/stars_400.gif", 5, "/img/samples/stars_500.gif", "else"), "Any Comment",height,width)

try this it works properly

Thanks,
Rahul Dey
Phanitha KuchiPhanitha Kuchi
I completed my challenge with following formula:

Lead Quality Helper:

IF(ISBLANK(Email), 0, 1) + IF(ISBLANK(Phone), 0, 1) + IF(ISBLANK(Company), 0, 1) + IF(ISBLANK(Title), 0, 1) + IF(ISPICKVAL(Industry, ""), 0, 1)


Lead Quality:

CASE(Lead_Quality_Helper__c,
    1, IMAGE("/img/samples/stars_100.gif", "one star"),
    2, IMAGE("/img/samples/stars_200.gif", "two stars"),
    3, IMAGE("/img/samples/stars_300.gif", "three Stars"),
    4, IMAGE("/img/samples/stars_400.gif", "four Stars"),
    5, IMAGE("/img/samples/stars_500.gif", "five Stars"),
       IMAGE("/img/samples/stars_000.gif", "zero Stars"))
Sam DawsonSam Dawson
Correction to above:
CASE(Lead_Quality_Helper__c,
    1, IMAGE("/img/samples/stars_100.gif", "1 star"),
    2, IMAGE("/img/samples/stars_200.gif", "2 stars"),
    3, IMAGE("/img/samples/stars_300.gif", "3 Stars"),
    4, IMAGE("/img/samples/stars_400.gif", "4 Stars"),
    5, IMAGE("/img/samples/stars_500.gif", "5 Stars"),
       IMAGE("/img/samples/stars_000.gif", "0 Stars"))