function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
balaji manikandanbalaji manikandan 

how to display a table with showing case objects details like case number along with the attachment details in same table?

I want to display all the cases with have attachments in a table along with the File name and other file related information in lighting component
 
GhanshyamChoudhariGhanshyamChoudhari
Hi,
try below code

apex
public class caselist {
    @AuraEnabled
    public static List<case> fetchcase(){
        return [select Id,casenumber,(Select Name From Attachments) from case limit 10];
    }

}

cmp
<aura:component controller="caselist"  implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
	  <aura:attribute name="setMeOnInit" type="case[]"  />
 <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    
     <table class="slds-table slds-table_bordered slds-table_cell-buffer">
         <thead>
            <tr class="slds-text-title_caps">
                <th scope="col">
                    <div class="slds-truncate" title=" Id">Id</div>
                </th> 
                 <th scope="col">
                    <div class="slds-truncate" title="Case Number">Case Number</div>
                </th> 
                 <th scope="col">
                    <div class="slds-truncate" title="Attachments">Attachments</div>
                </th> 
  
            </tr>
         </thead>
         <tbody>
            <aura:iteration items="{!v.setMeOnInit}" var="user">
               <tr>
                
                 <td><div class="slds-truncate">{!user.Id}</div></td>
                   <td><div class="slds-truncate">{!user.CaseNumber}</div></td>
                   <td><div class="slds-truncate">
                    <aura:iteration items="{!user.Attachments}" var="item">
                        {!item.Name}<br/>
 						 </aura:iteration>
                 </div></td>
                   
               </tr>
            </aura:iteration>
         </tbody>
      </table>
</aura:component>

controller
({
    doInit: function(component, event, helper) {
        var action = component.get("c.fetchcase");
        
        action.setCallback(this, function(response) {
            if (response.getState() == "SUCCESS") {
                var allValues = response.getReturnValue();
                component.set("v.setMeOnInit",allValues);
                console.log(JSON.stringify(allValues))
            }
        });
        $A.enqueueAction(action);
        
    },
    
})




Mark as best answer if it helps you.
Thanks,
Ghanshyam Choudhari
balaji manikandanbalaji manikandan
i cannot get the attachment deatils its only displaying case details
 
GhanshyamChoudhariGhanshyamChoudhari
Hi Balaji,
Remove limit from the query and make sure that in cases you have attachments.
[select Id,casenumber,(Select Name From Attachments) from case ]
Thanks
 
balaji manikandanbalaji manikandan
ya i have tried it already but it only displaying all the case in my org not file details
 
GhanshyamChoudhariGhanshyamChoudhari
select Id,casenumber,(Select Name From Attachments) from case  are you getting attachments details in the query?

 
balaji manikandanbalaji manikandan
No nothing
GhanshyamChoudhariGhanshyamChoudhari
please make sure that you are getting proper data in the query and once you get the data show on a lightning component.