3

I need to display content of attachment within iframe that is embedded in the particular sObject.

When you upload file from notes&Attachments related list on salesforce classic its type is attachment and i have hard coded link for displaying content of this attachment

/servlet/servlet.FileDownload?file='[id of attachment]'

But when i upload this file from lightning its type is file.

so is it possible to display content of ContentVersion I guess or what its type is in iframe in the same way as attachemnt in my example? enter image description here enter image description here

1 Answer 1

3

You will need to query the contentLinkDocument records with the EntityId equal to the record Id .

And also ContentLinkDocument will give you Id of the content Document and you will need a query against content document to get the necessary file

SELECT ContentDocumentId FROM ContentDocumentLink WHERE LinkedEntityId = '[RECORD ID]'

Then SOQL on ContentDocument

Select Id ,Title from ContentDocument Where ID In :[CONTENTDOCUMENTLIST]

Update

If you use Files or content related object there is a simple event with new lightning namespace which can be used

Here is a sample quick POC

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes" access="global" >
  <aura:attribute name="contentId" type="String" default="069B00000015QMwIAM"/>
 <lightning:button variant="brand" label="Preview Reciept" onclick="{!c.preview }" />

Note that the default here is the Id of the content document .

The controller code for same is below

({
  preview : function(component, event, helper) {
   $A.get('e.lightning:openFiles').fire({
    recordIds: [component.get("v.contentId")]
   });
  }
})
6
  • in such a way i can only fetch ContentDocument object, but I need to render its content
    – ketchyn
    Commented Nov 4, 2016 at 13:57
  • rendering can be done via new event openfiles .You will fire that and a modal will render automatically . Commented Nov 4, 2016 at 15:07
  • unfortunately it does not resolve my problem, first I need to display content within iframe and also I can't open attachment in such a way only content document files, when I'm trying substitute id of attachemnt to default value of attribute '<aura:attribute name="contentId" type="String" default="00P58000005CoxPEAS"/> ' i'm getting error
    – ketchyn
    Commented Nov 6, 2016 at 18:21
  • In lightning experience the attachment is stored in the contentversion object .So this is the content document Id Commented Nov 6, 2016 at 20:43
  • no, if file's type is Attachment, we can't see it in Contentversion object
    – ketchyn
    Commented Nov 7, 2016 at 14:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .