function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
gbrown17gbrown17 

Display attachments in VF page

I'm hoping someone could help me out. I'm trying to display attachments (pictures) in a VF page that are attached to a record. I have searched for a solution on the boards but none of them have seemed to work. Any suggestions? Much appreciated. Thanks, Greg
Best Answer chosen by Admin (Salesforce Developers) 
Abhay AroraAbhay Arora

String curroppid='0064000000AJzIIAA1';

 

Opportunity oo = [Select o.Name, o.Id, (Select Id, IsNote, Title From NotesAndAttachments) From Opportunity o where o.id=:currOppid limit 1];

List<NoteAndAttachMent> n=oo.NotesAndAttachments;

 

//process the list for each record to recreate a URL back to the Note or Attachment, or, depending on your need, different URLs for notes and attachments.

 

If above is what you need pleae mark as solved

 

 

 

All Answers

Abhay AroraAbhay Arora

String curroppid='0064000000AJzIIAA1';

 

Opportunity oo = [Select o.Name, o.Id, (Select Id, IsNote, Title From NotesAndAttachments) From Opportunity o where o.id=:currOppid limit 1];

List<NoteAndAttachMent> n=oo.NotesAndAttachments;

 

//process the list for each record to recreate a URL back to the Note or Attachment, or, depending on your need, different URLs for notes and attachments.

 

If above is what you need pleae mark as solved

 

 

 

This was selected as the best answer
gbrown17gbrown17

Thanks for the feedback - I noticed this is for an opportunity.  I actually want to pull attachments from a custom object.  What modifications do  I have to make to the code to reflect the custom object.  Here is what I'm thinking (in bold), let me know if I'm correct...

 

String curroppid='0064000000AJzIIAA1';

 

Opportunity oo = [Select o.Name, o.Id, (Select Id, IsNote, Title From NotesAndAttachments) From Opportunity o where o.id=:currOppid limit 1];

List<NoteAndAttachMent> n=oo.NotesAndAttachments;

 

//process the list for each record to recreate a URL back to the Note or Attachment, or, depending on your need, different URLs for notes and attachments.

Abhay AroraAbhay Arora

Hi Please replace the opportunity id with the record id of your custom object also in query do the same