+ Start a Discussion

Can we refer static resources in List View Button Salesforce

i made a list button for a custom object.In this button when on click i have to run javascript.i have to include jQuery in my page.can anyone please tell is it possible to refer it using $Resource.Bootstrap or i have to use a cdn url for referring to it.i read some where its better to include these jquery and bootstrap file from static resource for performance reason.please clarify.

Best Answer chosen by Admin (Salesforce Developers) 
Advanz Knowledge SystemsAdvanz Knowledge Systems



There is a work around for this. You can access static resource by using a hard coded URL as follows;
However, this will be problemantic because Salesforce does caching, and I believe the $Resource variable is clever enough to deal with cache and cache busting. If you use this variable, you will have problems that when you update your resource, anything referncing it will get an older version.
If you navigate to your static resource in Salesforce and click the "View File" URL, you will see a the a URL like this; https://yourorg.my.salesforce.com/resource/1311983211000/yourCustomResource.js
The string of thirteen digits is time represented in epoch format, with three 0's padded onto the right. This is basically to help with cache control.
So, for our work around, we need to some "cache busting". Unfortunately, we are limited to Salesforces validation/date functions, none of which will return time in epoch representation, so we need to get creative.
Using the following REQUIRESCRIPT statement should work;
{!REQUIRESCRIPT('/resource/' &  LEFT(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(TEXT(NOW()),':',''),'-',''),' ',''),10) & '000/yourCustomResource.js')}
Now that there is such an **bleep** ugly workaround to not having $Resources available in Custom Javascript Buttons, I hope salesforce will be justly motivated to make it available! :)