Activity Forums Salesforce® Discussions How can we get the static resources dynamically in visualforce page in salesforce?

  • Vikas Kumar

    Member
    January 23, 2017 at 10:18 am

    Hi Mohit,

    You can get the URL using the following util class.

    public class StaticResourceURL
    {
    // Pass the resource name
    public static String GetResourceURL(String resourceName){

    // Fetching the resource
    List<StaticResource> resourceList= [SELECT Name, NamespacePrefix, SystemModStamp FROM StaticResource WHERE Name = :resourceName];

    // Checking if the result is returned or not
    if(resourceList.size() == 1){

    // Getting namespace
    String namespace = resourceList[0].NamespacePrefix;
    // Resource URL
    return '/resource/' + resourceList[0].SystemModStamp.getTime() + '/' + (namespace != null && namespace != '' ? namespace + '__' : '') + resourceName;
    }
    else return '';
    }
    }

    for more info Go through

    http://forceguru.blogspot.in/2012/05/static-resource-url-in-apex.html

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos