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
Janno RipJanno Rip 

Declare Static Resource as a variable to assign its value through commandbutton


I have the following code:
<apex:mapMarker position="{!war.GeoLocPosition__c}" title="{!war.Name}" 
                    icon="{!IF(war.AE_letzte_12_Monate__c > 5000,URLFOR($Resource.ms_star),
                            IF(war.AD_MS_Rel_Anzahl_bez__c <= currentAccount.AD_MS_Rel_Anzahl_bez__c && war.WirtschaftszweigWZ08__c = currentAccount.WirtschaftszweigWZ08__c && war.Mitarbeiternzahl_final__c = currentAccount.Mitarbeiternzahl_final__c,URLFOR($Resource.perfect_fit),
                            IF(war.Accountinhaber_Text__c= 'JOB SHOP',URLFOR($,

What I am trying to fix is that I do not want a "hard copy" image for my icon: URLFOR($Resource.ms_star)

I want to be a variable, sth like: URLFOR($Resource.imageVar) 

Then with a command Link I would assign a specific value (the name of the image inside the static resource) to that variable:
<apex:commandLink action="{!setCenter}" value="{!war.ShippingStreet} ,{!war.ShippingPostalCode} {!war.ShippingCity}" reRender="geomap">
       <apex:param name="image" value="green" assignTo="{!imageName}"/></apex:commandLink>

So far I figured that "imageVar" has to be a variable in my class so I tried:
Public string imageName {get;set;}
And in my visualforce page:
<apex:page standardcontroller="Account" extensions="FindNearbyController" docType="html-5.0" lightningStylesheets="true" action="{!findNearby}"> 
    <apex:variable var="imageVar" value="{!imageName}"/>
What am I am hoping to achieve is that the commandLink passes the value "green" to the variable "imageName" which then gets used as Static Resource for my icon. Obviously there is an png called "green" in my static resource. However I don't get the syntax right for the variable inside the URLFOR. I am receiving: 

*Static Resource named imageVar does not exist. Check spelling.*

Best Answer chosen by Janno Rip
Janno RipJanno Rip
I figured it out after all. The problem was I did not use zip.file for my static resource. I changed to

which did the trick. Then I assigned via the commandLink the new image which is also part of the zip file:
<apex:param name="image" value="/green.png" assignTo="{!imageName}"/>