1

I am developing a package, where i have to display a set of images. This images can be customize able according to the need of user. For this i have a set of default and if the user want to display his own images he have to create a static resource and after that need to create a record with the static resource name and i am checking in my Vf page i am checking for whether the record with static resource is there if yes the display the image uploaded by the user else display the default image i my package. But after when i packaged it and try to test it on different environment it is getting error that the static resource name does not exist but the static resource is their and i have created the record for it. My code: Vf page

<div class="item active"> 
          <apex:image rendered="{!if(sr.size > 0,  false, true)}" url="{!URLFOR($Resource[StaticResourceName], image1)}" alt="First slide"  />             
          <apex:image rendered="{!if(sr.size > 0, true, false)}" url="{!URLFOR($Resource[StaticResourceName], image1)}" alt="First slide" />
      </div>
      <div class="item">
          <apex:image url="{!URLFOR($Resource[StaticResourceName], image2)}" alt="second slide" rendered="{!if(sr.size > 0, false, true )}" />
          <apex:image url="{!URLFOR($Resource[StaticResourceName], image2)}" alt="second slide" rendered="{!if(sr.size > 0, true, false)}"/>
      </div>
      <div class="item">
          <apex:image url="{!URLFOR($Resource[StaticResourceName], image3)}" alt="third slide" rendered="{!if(sr.size > 0, false, true)}" />
          <apex:image url="{!URLFOR($Resource[StaticResourceName], image3)}" alt="third slide" rendered="{!if(sr.size > 0, true, false)}"/>
      </div> 

controller :

   if(sr.size() > 0 ){            
        StaticResourceName = sr[0].name;
        image1 = 'Slider/1.jpg';
        image2 = 'Slider/2.jpg';
        image3 = 'Slider/3.jpg';
        //image4 = 'Slider/4.jpg';
        }
    else{            
        StaticResourceName = 'ResourceFile';
        image1 = 'rf/Slider/1.jpg';
        image2 = 'rf/Slider/2.jpg';
        image3 = 'rf/Slider/3.jpg';
        //image4 = 'rf/Slider/4.jpg';
        }
    }

I have changed the {!URLFOR($Resource[StaticResourceName], image3)} I it is working perfectly on the developed env but when it is installed in different env for testing it gives error.
Can any body here help me to get the solution on it.

  • i am getting this error : Static Resource named Slider does not exist. Check spelling Error is in expression '{!URLFOR($Resource[StaticResourceName], image1)}' in component <apex:image> in page cm_f:dashboardhome Error evaluating dynamic reference 'Slider' – AnuRaj Oct 23 '13 at 8:38
  • Is your package a managed package (with a namespace prefix) or not? – Keith C Oct 23 '13 at 18:09
  • yes it is a managed package with prefix cm_f__. But i try the solution which you have suggested but it does't work. I am getting same error as above with prefix name in it. – AnuRaj Oct 24 '13 at 4:26
  • Ok. All I can suggest is that you add a small test page and experiment with various constant values for x and y in {!URLFOR($Resource['x'], 'y')} until you figure it out... – Keith C Oct 24 '13 at 7:07
1

After packaging, you will have to include the namespace prefix in the resource reference for the default content that is in your package:

StaticResourceName = 'xyz__ResourceFile';

This is how a locally added resource called 'ResourceFile' (because it does not have a namespace prefix) is distinguished from the resource 'xyz__ResourceFile' in the package.

While you can query for this prefix (e.g. the StaticResource object has a NamespacePrefix field as well as a Name field), a common suggestion is to just hard code it.

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.