Using Variable for Static Resource

Did you ever came across such requirement, when you have your static resource name in a variable and you have to use that variable to access static resource on your visualforce page. Lets see Using Variable for Static Resource.

Lets understand this with an example.
We have 3 static resources for 3 colours Red, Yellow and Green. On the Contact Object we have a pick-list field Colour (Colour__c) which have values Red, Yellow and Green.
Now we have a custom visualforce page and Apex class, the page shows some basic information of the contact record and it should show image stored in the static resource for the colour.

To achieve this We have to use

If we have name of static resource in an apex variable.

On the visualforce page we have to use


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.