You need to sign in to do that
Don't have an account?
Luciano Roberto
How display list attachments of Custom object
Hello Folks,
I am creating a Lightning component to display the list of attachments related to registering a custom object. Could check where I am going wrong, because nothing is displayed.
Thanks
I am creating a Lightning component to display the list of attachments related to registering a custom object. Could check where I am going wrong, because nothing is displayed.
AttachmentList.cmp --------------------------------------------------------------------------------- <aura:component implements="forceCommunity:availableForAllPageTypes,force:hasRecordId" access="global" controller="AttachmentListController"> <aura:attribute name="recordId" type="Id" required="true"/> <aura:attribute name="files" type="List"/> <aura:handler name="init" value="{!this}" action="{!c.doInit}"/> <span class="text-blue"> <!-- <aura:iteration items="{!v.record.Attachments}" var="obj"> --> <aura:iteration items="{!v.files}" var="obj"> {!obj.Title} <br/> </aura:iteration> </span> </aura:component>
AttachmentListcontroller.js -------------------------------------------------------------------------------------------------- ({ doInit : function(component, event, helper) { $A.enqueueAction(component.get('c.getList')); }, getList: function(component, event, helper) { var action = component.get("c.getContentDocs"); action.setParams( { arecordId : component.get('v.recordId') }); action.setCallback(this, function(actionResult) { component.set('v.files',actionResult.getReturnValue()); }); $A.enqueueAction(action); }, })
AttachmentListController.apxc ------------------------------------------------------------------------------------------------------------ public class AttachmentListController { @AuraEnabled public static List<ContentDocument> getContentDocs(Id arecordId) { List<ContentDocumentLink> CDLs = [SELECT ContentDocumentId FROM ContentDocumentLink WHERE LinkedEntityId = :arecordId]; //List<ContentDocumentLink> CDLs = [SELECT ContentDocumentId FROM ContentDocumentLink WHERE LinkedEntityId = :'a08M000000BuU4vIAF']; if (CDLs.size() < 1) return new List<ContentDocument>(); // Make a List of ContentDocument IDs List <Id> CDIdList = new List <Id> (); for (ContentDocumentLink nextCDL : CDLs) { CDIdList.add(nextCDL.ContentDocumentId); } List<ContentDocument> entries = [SELECT Id, Title, FileType FROM ContentDocument WHERE ContentDocument.Id IN :CDIdList]; return entries; } }
Thanks
You are doing absolutely fine. just change some code->
1. first remove required attribute from recordId because if you methion recordId as required thn you have mention some default values.
2. Uncomment controller method logic.
You can use this code ->
AttachmentList.cmp -> AttachmentListcontroller.js
AttachmentListController.apxc
Now first try to upload any file to any record, put this component on record page and see the results. It will work.
Please mark as best answer if it helpful.
Thanks
All Answers
You are doing absolutely fine. just change some code->
1. first remove required attribute from recordId because if you methion recordId as required thn you have mention some default values.
2. Uncomment controller method logic.
You can use this code ->
AttachmentList.cmp -> AttachmentListcontroller.js
AttachmentListController.apxc
Now first try to upload any file to any record, put this component on record page and see the results. It will work.
Please mark as best answer if it helpful.
Thanks
Thank you very much Arun Parmar's,
Worked perfectly!!
I just need now to create a link to download the file, I'm afraid how to help me?
If you can help me with my other question about downloading the file, follow the link in the other topic. Thank you!
https://developer.salesforce.com/forums/ForumsMain?id=9062I000000IMJ9QAO#!/feedtype=SINGLE_QUESTION_DETAIL&dc=Lightning&criteria=OPENQUESTIONS&id=9062I000000IMQZQA4