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
Scott.MScott.M 

Referencing Local Static Resources in a Managed Package

Hi,

 

Is there a way to reference a locally created static resource from within a managed package? 

 

I thought that using the c__ namespace might work however it doesn't resolve properly. For example if I have visualforce page in my managed package that includes a locally created visualforce page. Any reference to the a local static resource causes an error, even if the namespace is appended 

 

{!$Resource.testbg} //Can't find the resource

{!$Resource.c__testbg} //Still can't find the resource 


Any ideas on how to get around this?

 

 

bob_buzzardbob_buzzard

I don't think you'll be able to do this.  The problem would be that there would be a dependency within the managed package that a local resource would have to be present wherever the managed package was installed, and I don't see how that could be enforced.  I suspect you'd also hit problems whenever you tried to upload the managed package, as the resource reference would error at that point.

 

Local interaction with a managed package would normally be the other way around, in that local pages could rely on managed package functionality.  

 

Can you tell us a bit more about why you are trying to do this?

 

 

Scott.MScott.M

That's true,

 

However what we're doing is similar to cmsforce in the sense that we use <apex:include> in our managed package page to load in pages that are user created so while our pages don't have any local references the pages being loaded can.

 

The interesting thing is that if I upload the static resources in a seperate organization as a managed package and install that then the references to the resources work fine. For example if I uploaded a managed static resources package with namespace test and then in the local page reference one of the resources with {!$Resource.test__myResource} then it works fine. It's only the local namespace that doesn't work.

 

Thanks! 

 

Scott

Jaap ScheperJaap Scheper
Why would one try to find a Local static resource from a managed package?
I have a usecase:

My managed package contains a class Util_Test, where you can set a mock:
 
global static void queueResponse(String resourceName, Integer httpCode) {
    StaticResourceCalloutMock mock = new StaticResourceCalloutMock();
    mock.setStaticResource(resourceName);
    mock.setStatusCode(httpCode);
    mock.setHeader('Content-Type', 'application/json');
    someQueuedMultiRequestMock.queueMock(mock);
    Test.setMock(HttpCalloutMock.class, someQueuedMultiRequestMock);
}

From the local org, you just have to call that method, providing the name of the Static Resource and the httpCode, and Salesforce does the rest (which is: mocking a response as soon as you do a callout). 
Is the idea.
Callouts, by the way, are done in that package is well. The local code calls a HttpClient class in the package to do callouts.

This line: mock.setStaticResource(resourceName); should take references to local static resources as well, in my opinion.