+ Start a Discussion
Ralph CallawayRalph Callaway 

Using Static Resources in Image Formula Field

Is there a DOCUMENTED way to use a static resource as an image in a formula field?  I'm trying to create an 'action link' that looks like a command button and need to find a place to store the background image for the link in a way that is environment agnostic

 

I'd hoped this would work, but $Resource doesn't seem to be recognized in formula fields (works fine in visualforce formulas).  

HYPERLINK('/apex/createAgreement?id=' +  Id ,  IMAGE( $Resource.Create_Agreement_Button , 'Create Agreement' )  , '_top')

 

It appears that this will work, but I'd rather not depend on undocumented functionality to accomplish this.  Particulary given I'd like to add this to a managed package at sometime and in theory there could be an identically named resource that alread exists in the org.

HYPERLINK('/apex/createAgreement?id=' +  Id ,  IMAGE( '/resource/Create_Agreement_Button' , 'Create Agreement' )  , '_top')

 

Documents are also a reasonable approach, but I don't know how to use them across multiple environments where I won't no the document id.

Best Answer chosen by Admin (Salesforce Developers) 
tselvamtselvam

It is very simple .first u upload image in resourse . and then file open --> view file  then copy url.   for example

 url may be https://ap1.salesforce.com/resource/1329402101000/Image1 

 then edit the url like this  ' /resource/Image1' 

 

IMAGE(
CASE( {!Rating__c},
1, " /resource/Image1'", 'None','No Image'
)

All Answers

MiddhaMiddha

Its not possible as of now and posted as an Idea, you can vote for it though.

Ralph CallawayRalph Callaway

Hey Greg, can you post a link? I can't seem to find it.

SunnykoolSunnykool

I think we can have the formuales field returning text and embed an Image tag within formaule field. But the problem is while packaging the stuff the images are not rendered unless we prepend the namespace prefix with the Resource name. In case, if you requirement is suffice by the sample images given by Salesforce , then this should be fine. Following link gives some more information on that.

 

http://www.salesforce.com/community/assets/docs/Sample_Image_Formula_Fields_Customization_Guide.pdf

 

Cheers

Sunny

SunnykoolSunnykool

else, what you can do is hardcode the namespace prefix before building the manage package in the formuale field.

Just prepend the namespace before the resource name and it works like a charm.

 

I understand this to be a temporary workaround but cannot wait for the Idea to be implemented though voted for the idea which Gulshan has raised.

 

Please mark this post as resolved in case this works out for you.

Juan SpagnoliJuan Spagnoli

Ok... thinking about what you are saying, i did this:

 

IMAGE('/resource/' + $Setup.Package_Resources__c.Prefix__c + $Setup.Package_Resources__c.Name__c + '/images/flags/' + Name +'.gif', Name)

 

Where "Package_Resources__c" is a Custom Setting, with 2 fields: "Prefix" and "Name". In prefix i'm saving the prefix of the package, and in name the static resource name.. so it works fine. :)

 

 

Thank you guys

tselvamtselvam

It is very simple .first u upload image in resourse . and then file open --> view file  then copy url.   for example

 url may be https://ap1.salesforce.com/resource/1329402101000/Image1 

 then edit the url like this  ' /resource/Image1' 

 

IMAGE(
CASE( {!Rating__c},
1, " /resource/Image1'", 'None','No Image'
)

This was selected as the best answer
rayjguyrayjguy

That's great tselvam.

 

I'd just highlight for people that you can (and should) take the resource Id out of the URL as you've done.  It's then safe to migrate between environments.

 

Cheers,

Ray

agum34agum34

I've always used the Static Resource ID which was a pain to manage new versions, thanks @tselvam for this simple solution.

ItsMeSolItsMeSol

My question..What if i log in as other user... I cant see the image referencing from static resource.

Susane ASusane A
@tselvam, it worked great in the detail page, although in the object home page were is a list of "recent items" it does not work, it brings up the 'alt' message. So, to also get the icon personalized in the home I use document obj. Thank you