0

I need help to make a soql to get the images from ContentVersion based on caseId

We have 3 objects: ContentDocument ContentVersion ContentDocumentlink

ContentDocument is parent of ContentVersion and ContentDocumentLink

ContentVersion has versiondata(that is binary data) ContentDocumentLink having case id(Fieldname is LinkedEntityId)

I need to create a SOQL that provides version data of ContentVersion based on linkedentityID ( case- ID) when I use this query

select versiondata from contentversion where contentdocumentid in(select contentdocumentid from contentdocumentlink where linkedentityid in(select id from case))

Than it is giving the error like Entity 'contentdocumentlink' is not supported for semi join inner selects

It is giving error like semi join is not supported.

1 Answers1

0

This works with any id (any object that you marked as allow attachments)

SELECT ContentDocument.LatestPublishedVersion.VersionData 
FROM ContentDocumentLink 
WHERE LinkedEntityId = '...'

Or top-down (useful if you need multiple records and their files)

SELECT Id, CaseNumber, Subject, 
    (SELECT ContentDocument.LatestPublishedVersion.VersionData FROM ContentDocumentLinks)
FROM Case
WHERE Id = '...'
eyescream
  • 18,088
  • 2
  • 34
  • 46
  • If I am using this query SELECT ContentDocument.LatestPublishedVersion.VersionData FROM ContentDocumentLink WHERE LinkedEntityId in(select id from case) than it is giving me object form soql so I want to know what it will return ContentDocument.LatestPublishedVersion.VersionData. I need binary data from Content version based on case id but I need to use only with soql – Ankur Goyal Dec 23 '22 at 10:04
  • "object" as in useless JavaScript "[Object object]"? Run it from sfdx, data loader or workbench.developerforce.com to see the result properly. What you'll get depends on API used. REST API will have a link to retrieve the raw binary, SOAP API (like python's "simple Salesforce" library) will give back base64-encoded file payload – eyescream Dec 23 '22 at 16:56
  • See my answer https://stackoverflow.com/a/60284736/313628 for more info – eyescream Dec 23 '22 at 16:58