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
MohaMoha 

Dynamic reference to Static Resource in Managed Package

Hello i'm developping a managed package, and i would like to know how can the customer change an image or a file which is included in a visualforce page, i know that it's not possible with static ressource since we cannot modify a static ressource with a managed package so any snippet of Code for Help i found this snippet but it's not complet if there is anyone who can help that would be great

 

 public String getLogo() {
    	if (theFormat != null && theFormat.Logo__c != null && theFormat.Logo__c.length() > 0) {
	    	List<Document> docs = [ SELECT Name, Id From Document WHERE Name = :theFormat.Logo__c LIMIT 1 ];
	    	if (docs.size() > 0) {
	    		Document doc = docs[0];
		    	string imageid = doc.id;
		    	imageid = imageid.substring(0,15);
		    	return '<img src="/servlet/servlet.FileDownload?file=' + imageid + '"/>';
	    	}
    	}
    	
    	return '';
    }

 

 <apex:outputText value="{!Logo}" escape="false" />
Bhawani SharmaBhawani Sharma
What we didi recently is, I took the image URL in query starting parameter and placed the banner image from that:
URL: www.something.com?banner=/resource/4567/banner.png

on Page
<apex:image URL="{!$CurrentPage.Parameters.banner}" />
MohaMoha

Hello, thanks for the reply but i don't get how this is going to help ??? my case is that i have a managed package and when the customers install my package they need to change my logo on site with their own logo and since it's not possible with static ressource how it's going  to be possible with ur answer i didn't get it, thanks for the help

thanks,

Bhawani SharmaBhawani Sharma
Can't you put your Logo path in custom setting and use that in code. This way, customers will always have the options to change it.
MohaMoha

i don't see how this is possible ??? and my customer should always write code to do that, i need something that allow my customer without code just customising to change the logo, if you have seen the Code Above Using Document Object

public String getLogo() {
String logo='MyLogo';
if (logo.length() > 0) {
List<Document> docs = [ SELECT Name, Id From Document WHERE Name = :logo LIMIT 1 ];
if (docs.size() > 0) {
Document doc = docs[0];
string imageid = doc.id;
imageid = imageid.substring(0,15);
return '<img src="/servlet/servlet.FileDownload?file=' + imageid + '"/>';
}
}

return '';
}


<apex:outputText value="{!Logo}" escape="false" />

 

but this doesn't retrieve the Image, i guess the error is in the <apex:outputtext> ?

Kiran  KurellaKiran Kurella

Try this:

 

Replace the following line

 

return '<img src="/servlet/servlet.FileDownload?file=' + imageid + '"/>';

 

with

 

return '/servlet/servlet.ImageServer?id='+imageid;    or

 

return '/servlet/servlet.FileDownload?file=' + imageid;

 

 

Also, replace 

 

<apex:outputText value="{!Logo}" escape="false" />

 

 

with

 

<img src="{!Logo}" />

 

 

MohaMoha
Hello, thanks for the reply i tried what your solution but unfortunately i don't have errors while compiling and it doesn't show the Image on the Site