[SalesForce] Access Custom Setting global variable from Static Resources


I'm using the above to access custom setting on the page. But when I move the script to static resources and try to access it from there the value is not being fetched. Any help is much appreciated thanks!

Best Answer

Static resources are... static. There is no pre or post processing of their contents. Instead of putting globals from Visualforce code in your javascript, try putting some JavaScript in your Visualforce code.


  1. Before your script loads, create some JavaScript bridging code:

        $Setup = window.$Setup || {};
        $Setup.MyCustomSet__c = $Setup.MyCustomSet__c || {};
        $Setup.MyCustomSet__c.URL__c = '{!$Setup.MyCustomSet__c.URL__c}';
  2. Now in your javascript (in a static resource) use the variables as if they were VF, without {!}

    function errorHandler() {

If the naming is consistent, your front-end team can pluck the values straight out of the JavaScript and nobody has to invent anything. Also has the benefit of masking variations due to namespace prefixes.