0

I have a simple formula field in salesforce which show particular image based on another picklist, as below.

IMAGE(IF(ISPICKVAL(Rating__c,"1 Star"), "/img/samples/stars_100.gif", IF(ISPICKVAL(Rating__c,"2 Star"), "/img/samples/stars_200.gif", IF(ISPICKVAL(Rating__c,"3 Star"), "/img/samples/stars_300.gif", IF(ISPICKVAL(Rating__c,"4 Star"), "/img/samples/stars_400.gif", IF(ISPICKVAL(Rating__c,"5 Star"), "/img/samples/stars_500.gif", IF(ISPICKVAL(Rating__c,"0 - New"),"/servlet/servlet.FileDownload?file=0157F000001hDuD", IF(ISPICKVAL(Rating__c,"-1 - No"),"/servlet/servlet.FileDownload?file=0157F000001hDu8", "/img/samples/stars_000.gif" ))))))), "")

When i try to sort by this field in List view, it sorts in wrong order, So i was wondering how to force this field to sort in correct order.

2 Answers 2

3

The formula is going to end up being sorted alphabetically by file name. You would necessarily need to prefix the formula with some sort of text that can be sorted. There's absolutely no way to have just an image and still have it sorted correctly. It has to do with the generated code that IMAGE produces. A better idea would be to use Static Resource files so you can control the file names.

CASE(
    Rating__c,
    "1 Star", "/resource/stars11",
    "2 Star", "/resource/stars12",
    "3 Star", "/resource/stars13",
    "4 Star", "/resource/stars14",
    "5 Star", "/resource/stars15",
    "0 - New", "/resource/stars01",
    "-1 - No", "/resource/stars00",
    ""
)

By doing this, you can control the sort order.

0
0

How @sfdcfox says the formula is going to end up being sorted alphabetically by file name. But you can add paramaeter in the url to try to sort them. In your example you use differents url images (standard and customs). But if you could upload your own images, you'll have the same url base with diferent paramenter, similar to your last two image (/servlet/servlet.FileDownload?file=XXXXXXXXX"). You could add a parameter as "sort=1","sort=2"... in the url. For example:

/servlet/servlet.FileDownload?sort=1&file=XXXXXXXXX"

In other hand you could use static resource images and use the file name to order it.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .