You need to sign in to do that
Don't have an account?
SalesforceLearner
Display case information using Lightning component
I want to display cases related to loggedin user account. It is displaying empty list(it is not returning any values). When tried in query editor the query is working I am not understanding where i am making mistake can anyone pls help me with this ?
here is my code:
Controller:
Component Controller:
here is my code:
Controller:
public class CaseInformation{ @AuraEnabled public static List<Case> getCases() { ID contactId = [Select contactid from User where id =: Userinfo.getUserid()].contactId; if(contactId == null) { return NULL; } ID AccID = [Select AccountID from Contact where id =: contactid ].AccountId; if(AccID == null){ return NULL; } System.debug('AccountId :' + AccID + 'ContactId:' + contactId); List<Account> allAssocaiatedAccounts = [Select Id, name, industry from Account where Id =: AccID]; if(allAssocaiatedAccounts.size() != 0){ return [Select CaseNumber,Status,Priority,Type,Subject,AccountID from Case where AccountID IN: allAssocaiatedAccounts]; } else { return NULL; } } }Lightning Component:
<aura:component controller="CaseInformation"> <aura:attribute name="caseRows" type="Object[]"/> <aura:handler name="init" value="{!this}" action="{!c.doInit}" /> <aura:iteration var="cas" items="{!v.caseRows.Cases}"> <tr class="border_bottom"> <td > {!cas.CaseNumber} </td> <td > {!cas.Subject} </td> <td >{!cas.Status}</td> <td> <ui:outputDate format="MMM dd yyyy" value="{!cas.CreatedDate}"/> </td> <td >{!cas.Account.Name}</td> </tr><hr class="hrcolclass" /> </aura:iteration> </aura:component>
Component Controller:
({ doInit : function(component, event, helper){ helper.getAllCases(component); } })Helper:
({ getAllCases : function(component, event, helper) { var action = component.get("c.getCases"); action.setCallback(this, function(a){ component.set("v.caseRows", a.getReturnValue()); }); $A.enqueueAction(action); } })
<aura:component controller="CaseInformation">
<aura:attribute name="caseRows" type="Case[]"/>
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<aura:iteration var="cas" items="{!v.caseRows}">
<tr class="border_bottom">
<td > {!cas.CaseNumber} </td>
<td > {!cas.Subject} </td>
<td >{!cas.Status}</td>
<td> <ui:outputDate format="MMM dd yyyy" value="{!cas.CreatedDate}"/> </td>
<td >{!cas.Account.Name}</td>
</tr><hr class="hrcolclass" />
</aura:iteration>
</aura:component>
Use this:
<aura:attribute name="caseRows" type="List[]"/>
I think this will work smoothly. Mark this as answer if works.
Cheers
you can use either or Also, the get method simplifies to
Sorry if this is two years too late but hopefully it will help others.
Select CaseNumber,Status,Priority,Type,Subject,Account.Name, CreatedDate from Case
Can anyone help to fetch cases based on account selection?
can you please help with this. it really urgent for me.
Thank you so much for your help!
But it looks like @wire(getAllCase) should be plural as in @wire(getAllCases)
and the function need to change to what I sent before.
Hope this helps.
I would change the parameter name passed in to avoid confusion. e.g. (String accId).
then "WHERE AccountId =: accId" is clearer.
Have you tried adding diagnostics to see what is listed.
Yes; I have check that diagnostics
system.debug('accountId in getAllCases = '+accId); // Didn't get aacid = null
system.debug('lstCases...'); // null
system.debug(lstCases); // list of all cases display not particular account
As I say, I'm not familiar with LWC but it'll be structured something like this example:
Thanks for the help it's not working i have posted my updated logic if possible can you please let me know what should be the issue?