I want retrieve image from documents in not other notes like pdf,ext... please how to write soql query

  • 1
    Would you mind putting some more effort into your question ? Please explain us what you are trying to do, if there is a part that you already have and what parts you do not understand. That, and tagging the questions with the best related subjects will make it easier to answer this question. This entire site deals with salesforce, so the salesforce-crm tag should be avoided. You can edit your question to update it. – Samuel De Rycke Dec 24 '13 at 17:21
  • SELECT (SELECT Id FROM Attachments)FROM Property__c WHERE Property_Status__c = 'Active' ]; – user4955 Dec 24 '13 at 17:44
  • That is my code but in that i need only images – user4955 Dec 24 '13 at 17:44
  • 1
    Can you try to edit that code into your question ? tip: you can format it with the {} icon. Do you know how to identify 'images' from other attachments, is there a set of filetypes or extentions that you consider to be an image ? – Samuel De Rycke Dec 24 '13 at 18:10

As Sdry suggested in the comments please put some effort in before asking your questions

Assuming you want to retrieve related attachment for a records,what you have to do write a query on Attachment object...


see the example query below:

SELECT Id,Name FROM Attachments where ParentId ='id of the record for you want to query related attachments for' AND ContentType ='type of the attachment you want to retrive'

i have written sample code for you check below

Vf page:

 <apex:page Controller="Attachments">

<apex:pageBlock >
<apex:pageBlockTable value="{!LA}" var="a">
<apex:column value="{!a.id}"/>
<apex:column value="{!a.name}"/>
<apex:column value="{!a.contenttype}"/>


public class Attachments {

public List<Attachment> LA{get{
                                 return [SELECT Id,Name,ContentType FROM Attachment                     where ParentId ='0019000000CHVUl'];



results: resulting table

When i change the query in controller adding a filter with content type as below

return [SELECT Id,Name,ContentType FROM Attachment where ParentId ='0019000000CHVUl' AND contenttype in ('image/png','image/gif')];

Results table changes to..

enter image description here

  • 1
    Hey :D this is gonna sound harsh, but the same applies for answers :P. Mind explaining in your answer itself how such an query works, and how images can be identified ? – Samuel De Rycke Dec 24 '13 at 18:11
  • AND WHERE ContentType IN ('image/bmp', 'image/gif', 'image/jpeg', ...) should do the trick... en.wikipedia.org/wiki/Internet_media_type#Type_image seems like a good start – eyescream Dec 24 '13 at 23:11
  • No it will shows an error like unexpected token bmp,gif.... – user4955 Dec 25 '13 at 9:11
  • You are confused, i have custom object(pro) in that users will update different types of notes and attachments and i want to separate images and notes(pdf,excel...)and need to display all images in vf page – user4955 Dec 25 '13 at 14:29
  • 1
    i have given link in the answer please go through that page for all details on the attachment object – user4971 Dec 25 '13 at 14:41

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.