You need to sign in to do that
Don't have an account?
charlie_v
Record-Level Images in VF Sites Page
Hoping someone will have a good tip for this...
I have a custom object that I'm exposing on Sites.
Each record in the custom object has a screen shot image. The custom object has approximately 200 records.
Question #1: Are Static Resources the ONLY way to expose images in a VF Sites page?
If the answer is yes, then
Question #2: Does that mean every time I add a new record to my custom object, and that record includes a screen shot, I will need to update my static resource file before I can expose that image with the record on Sites?
No, there are a few other ways you could do this :
1) You can expose images in the 'Documents' tab if you've flagged them as 'externally available'
2) Probably the best way : You can expose attachments that exist on any object via Sites. Below you'll see a few snippets of code of a VF page and custom controller that do this
Controller : public class BowGalleryController { public List<Attachment> pics {get;set;} public Picture_Gallery__c gallery {get;set;} public BowGalleryController() { pics = [Select a.ParentId, a.Name From Attachment a where parentId = :System.currentPageReference().getParameters().get('id')]; gallery = [Select Id, Name, Description__c from Picture_Gallery__c where Id =:System.currentPageReference().getParameters().get('id')]; } } VF Page snippet : <ul class="gallery_demo_unstyled"> <apex:repeat value="{!pics}" var="p"> <li><img src="/bow/servlet/servlet.FileDownload?file={!p.Id}"/></li> </apex:repeat> </ul>
All Answers
No, there are a few other ways you could do this :
1) You can expose images in the 'Documents' tab if you've flagged them as 'externally available'
2) Probably the best way : You can expose attachments that exist on any object via Sites. Below you'll see a few snippets of code of a VF page and custom controller that do this
Controller : public class BowGalleryController { public List<Attachment> pics {get;set;} public Picture_Gallery__c gallery {get;set;} public BowGalleryController() { pics = [Select a.ParentId, a.Name From Attachment a where parentId = :System.currentPageReference().getParameters().get('id')]; gallery = [Select Id, Name, Description__c from Picture_Gallery__c where Id =:System.currentPageReference().getParameters().get('id')]; } } VF Page snippet : <ul class="gallery_demo_unstyled"> <apex:repeat value="{!pics}" var="p"> <li><img src="/bow/servlet/servlet.FileDownload?file={!p.Id}"/></li> </apex:repeat> </ul>
I recommend the following url to generate the correct link, so that you don't have to hard code the site path
{!URLFOR($Action.Attachment.Download, p.Id)}