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
PRASHANT BHARTIPRASHANT BHARTI 

Write a lightning component to display the open cases related to the logged in user

Write a lightning component to display the open cases related to the logged in user
Maharajan CMaharajan C
https://developer.salesforce.com/forums/?id=9060G0000005eghQAA

Thanks,
Maharajan.C
Khan AnasKhan Anas (Salesforce Developers) 
Hi Prashant,

Greetings to you!

Please try the below code, I have tested in my org and it is working fine. Kindly modify the code as per your requirement.

Apex:
public class DisplayOpenCasesC {
    
    @AuraEnabled 
    public static List<Case> getOpenCases(){
        List<Case> caseList=new List<Case>();
        caseList = [SELECT Id, CaseNumber, Subject, Type, Status FROM Case WHERE OwnerId =:UserInfo.getUserId() AND Status!='Closed'];
        return caseList;
    } 
}

Component:
<aura:component controller="DisplayOpenCasesC"
                implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
    
    <aura:attribute name="data" type="Object"/>
    <aura:attribute name="columns" type="List[]"/>
    
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    
    <lightning:datatable aura:id="casetable"
                         keyField="Id"
                         data="{!v.data}"
                         columns="{!v.columns}"
                         hideCheckboxColumn="true"/>
</aura:component>

Controller:
({
    doInit : function(component, event, helper) {
        component.set('v.columns', [
            {label: 'Case Number', fieldName: 'CaseNumber', editable: true, type: 'text'},
            {label: 'Subject', fieldName: 'Subject', editable: true, type: 'text'},
            {label: 'Type', fieldName: 'Type', editable: true, type: 'text'},
            {label: 'Status', fieldName: 'Status', editable: true, type: 'text'}
        ]);
        var action=component.get('c.getOpenCases');
        action.setCallback(this, function(response){
            var state = response.getState();
            if (state === "SUCCESS") {
                var rows = response.getReturnValue();
                component.set("v.data", rows);
                
            }
        });
        $A.enqueueAction(action);
    }
})

Application:
<aura:application extends="force:slds">
    <c:DisplayOpenCases/>
</aura:application>

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas