3

I have a static resource in my org 'Customer_Logo', inside that I have the logo of all my customer, called like : AccountNumber.jpg

I take the Account number in the controller of a VF page render as PDF and use this in VF page to take logo. Example:

<apex:image  url="{!URLFOR($Resource.Customer_Logo, 'images/'+ customerLogo + '.jpg')}" style="width: 100px;height: 100px"/>

where :

String customerLogo=[Select id,Account_Number__c from Account where...].Account_Number__c;

Sometimes I doesn't have all my customer logo so the resource is not found and inside the pdf a grey static image is shown. Is there a way to check if a static resource exists?

3

In your controller, you should be able to do this:

String customerLogo=[Select Account_Number__c from Account where...].Account_Number__c,
    tempUrl = '/resource/Customer_Logo/images/'+customerLogo+'.jpg',
    imageUrl = '/resource/defaultlogo';
try {
    new PageReference(tempUrl).getContent();
    imageUrl = tempUrl;
} catch(VisualforceException e) {
    // 404 error happened here
}
return imageUrl;

This code uses Apex Code to manually verify the image's existence before using the URL.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.