0

I'm trying to show Files Uploaded in Salesforce File.

I created a Folder in the Libraries part and uploaded the Files inside of it.

So i made a custom aura component to show those files.

So i made my APEX Controller like this :

public with sharing class FolderItemController {
    @AuraEnabled
    public static List<ContentFolderItem> getContentFolderItem() {
        String folderId = [SELECT Id FROM ContentFolder WHERE Name = :'Modes Opératoires ADV B2B'].Id;
        return [SELECT ContentSize,CreatedById,CreatedDate,FileExtension,FileType,Id,IsDeleted,IsFolder,LastModifiedById,LastModifiedDate,ParentContentFolderId,SystemModstamp,Title 
         FROM ContentFolderItem WHERE ParentContentFolderId = :folderId];
    }
}

And my Aura component like this.

ModesOperatoires.cmp :

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes" controller="FolderItemController">    
    <!-- Dynamically load the list of contacts -->
    <aura:attribute name="contents" type="List"/>
    <aura:attribute name="recordId" type="ContentFolderItem" />
    <aura:handler name="init" value="{!this}" action="{!c.init}"/>
    
    <lightning:card variant="Narrow" title="Modes Opératoires B2B/ADV" 
                        iconName="standard:contact">
            <!-- Iterate over the list of contacts and display them -->
            <aura:iteration items="{!v.contents}" var="content">
                <p>
                   File Title : {!v.content.Title}
                </p>
                <p>
                   File Size : {!v.content.ContentSize}
                </p>
                <p>
                   File Extension : {!v.content.FileType}
                </p>
                <p>
                   Owner : {!v.content.CreatedById}
                </p>
            </aura:iteration>            
        
        </lightning:card> 
</aura:component>

ModesOpertatoires.js :

({
    init: function(component, event, helper) {
        helper.getModesOperatoires(component);
    }
})

ModesOperatoiresHelper.js :

({
    getModesOperatoires : function(component) {
        var action = component.get("c.getContentFolderItem");
        
        //Set up the callback
        var self = this;
        action.setCallback(this, function(actionResult) {
            var state = actionResult.getState();
            console.log(state);
            console.log(actionResult.getReturnValue());
            console.log(component.isValid());
            if (component.isValid() && state === "SUCCESS") {
                component.set("v.contents", actionResult.getReturnValue());
            }            
        });
        $A.enqueueAction(action);
    }
})

But at the end, i can see the Data in my Browser Console but not in the Utility Bar Shortcut where i'm using the component.

enter image description here

If you guys can enlighten where my mistake is would help me a lot.

6
  • What is the purpose of recordId attribute in your component?
    – Mahmood
    Aug 3, 2020 at 11:38
  • To get the ID of my 2 Files in the Folder, but i'm wondering if it's not the reason of my issue. Aug 3, 2020 at 11:43
  • Can you try and see if setting of v.contents property inside the if statement is being executed.
    – Raul
    Aug 3, 2020 at 11:51
  • Like this ? if (component.isValid() && state === "SUCCESS" && "v.contents") { console.log("v.contents"); component.set("v.contents", actionResult.getReturnValue()); console.log(actionResult.getReturnValue()); } Aug 3, 2020 at 11:56
  • yes, like that.
    – Raul
    Aug 3, 2020 at 12:43

1 Answer 1

3

You have typo here. You can see your iteration happened already 2 times. Only data is not displaying.

In aura iteration we don't use V tag. Ref - Example in Aura Doc

Please try with this -

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes" controller="FolderItemController">    
    <!-- Dynamically load the list of contacts -->
    <aura:attribute name="contents" type="List"/>
    <aura:attribute name="recordId" type="ContentFolderItem" />
    <aura:handler name="init" value="{!this}" action="{!c.init}"/>
    
    <lightning:card variant="Narrow" title="Modes Opératoires B2B/ADV" 
                        iconName="standard:contact">
            <!-- Iterate over the list of contacts and display them -->
            <aura:iteration items="{!v.contents}" var="content">
                <p>
                   File Title : {! content.Title}
                </p>
                <p>
                   File Size : {! content.ContentSize}
                </p>
                <p>
                   File Extension : {! content.FileType}
                </p>
                <p>
                   Owner : {! content.CreatedById}
                </p>
            </aura:iteration>            
        
        </lightning:card> 
</aura:component>
3
  • 1
    good catch! v. in aura component is the new hide and seek champion after ;.
    – Raul
    Aug 3, 2020 at 13:08
  • 1
    It works perfectly, thank you very much. Aug 3, 2020 at 13:09
  • 1
    @Raul - yeah really :D
    – Ysr Shk
    Aug 3, 2020 at 13:11

You must log in to answer this question.

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