You need to sign in to do that
Don't have an account?

Get image path from static resource with Apex
I am building a dynamic html email with apex and want to store all of my images in a zipped static resource. How can I pull the image path / reference from the static resource to use in my string.
Currently I have:
but the path is not working as a reference.
Currently I have:
public static StaticResource static_resource = [SELECT Id,NamespacePrefix, name, SystemModStamp FROM StaticResource WHERE Name = 'banner' LIMIT 1]; String prefix = static_resource.NamespacePrefix; if( String.isEmpty(prefix) ) { prefix = ''; } else { //If has NamespacePrefix prefix += '__'; } String url_file_ref = '/resource/' + String.valueOf(((DateTime)static_resource.get('SystemModStamp')).getTime()) + '/' + prefix + + static_resource.get('Name') + '/image.png'; string lookingForURL = Url.getSalesforceBaseUrl().toExternalForm() +url_file_ref();
but the path is not working as a reference.
You can try below.
https://salesforce.stackexchange.com/questions/107584/accessing-static-resource-in-apex
Please mark as Best Answer if above information was helpful.
Thanks,