Is there anyway to create an image for a button with a variable title for use in a formula field?


A common request I get is to put buttons in the page layout itself as the buttons at the top tend to get overwhelming. Creating a faux button with a formula field has been a great approach, I create a button image with the title I need and upload to static resources and then create the formula field. For example

HYPERLINK('/apex/target?id='Id, IMAGE('/resource/myBtn', 'Do It'))

This approach is working great, but has two pain points, 1) I have to create a new image for the title of each new button (i.e. need a different button for "Send Email" and another for "Launch Batch"), and 2) I'm quickly creating an absurd number of static resources which is cluttering things up.

Is there anyway to get create the button image dynamically in Salesforce so I could pass in the title in the formula field and not have to keep creating buttons? For example

   IMAGE('/apex/buttonImg?title=Do+It', 'Do It'))

Or maybe

   IMAGE('http://buttonmaker.com?title=Do+It', 'Do It'))

There is no problem to link the image dynamically. In my example i will use a new static resource img where all my images are packed. For that i will create three images info-x.png (where x is a number from 1 to 3) and move them to a new folder 'icons'. This folder i will add to a new zip-archive with compression method 'storage'.

enter image description here

After that i will add it to the static resource:

enter image description here

Well now is a time to create a new formula field. In my formula i will reference the picklist field Status__c and output button image depending on that status:

HYPERLINK('/apex/test1', IMAGE('resource/img/icons/' + 'info-' + 
                                IF(TEXT(Status__c) = 'OK', '1', '2') + '.png',
                               'Info text'), 
          'Do It')

So for the status 'OK' the green button appears and for the 'ERROR' the red one.
The result looks like this:

enter image description here

You can use external picture path for the IMAGE type like http:/server.com/picgenerator?id=1. I hope this helps.

  • Thanks for the response. The sticking point for me has been creating all the buttons which I was hoping to highlight in my question, i.e. one image, the title is determined dynamically. You have an excellent solution for pictures in general, but I'd still need to create each new image manually. – Ralph Callaway Jun 8 '13 at 17:12

For simpler use cases try to go with record types and layouts, where you only show specific buttons. For more complex scenarios the only option a custom sidebar component that overwrites the button labels via javascript.

  • Thanks for the response. They need all the buttons, I'm just trying to figure out to get that same "button"-y image into a formula field with out having to create a new static resource each time. – Ralph Callaway Jun 7 '13 at 22:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.