0

I am having an issue returning the attachment details related to my caseId. Everything I have done should work but it isn't, I have managed to return the names ect within my dev console using the SOQL. The issue is it will not return to my component when the component is loaded on screen.

ApexController

@AuraEnabled
    public static Attachment getAtt(Id caseId){
        return ([Select id, ParentId, Name
                 From Attachment Where ParentId=:caseId]);
    }

Lightning Controller

doInit : function(component, event, helper) {
        component.set("v.isError", false)
        component.set("v.showEditView", false);
        component.set("v.errorMsg", "");
        //helper.getPicklistValue(component);
        var action = component.get("c.getAtt");
        action.setParams({
            caseId : component.get("v.caseId")
    });

    action.setCallback(this, function(a) {
        if (a.getState() === "SUCCESS") {
            component.set("v.Attachment", a.getReturnValue());
        }
    });

    $A.enqueueAction(action);
    },

LightningComponent

<aura:component controller="AmexComm_SecureMsgController" implements="forceCommunity:availableForAllPageTypes,force:hasRecordId" access="global">

    <aura:attribute name="Attachment" type="Attachment"/>
    <aura:attribute name="showListView" type="Boolean"/>
    <aura:attribute name="showCreateNew" type="Boolean"/>
    <aura:attribute name="showAttachment" type="Boolean"/>
    <aura:attribute name="lstSubs" type="Object[]"/>
    <aura:attribute name="isError" type="Boolean"/>
    <aura:attribute name="errorMsg" type="String"/>
    <aura:attribute name="caseId" type="String" default="{!v.recordId}"/>

    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>

    <h3 class="slds-section-title--divider" style="margin-left: 1.5rem; max-width: 657px;">Exisiting Attachments</h3>
    <h3 class="slds-section-title--divider" style="margin-left: 1.5rem; max-width: 657px;">
        <span class="text-blue"> {!v.Attachment.name}</span></h3>           <!-- pull attachments associated to case -->
    <h3 class="slds-section-title--divider" style="margin-left: 1.5rem; max-width: 657px;">
        <span class="text-blue"> {!v.Attachment.name}</span></h3>
    </aura:component>

1 Answer 1

2

Lightning components are case-sensitive. So you should use exact field names when you access any variables.

You have Name as field of Attachment in apex class but you are trying to access name in your lightning component. Change it to Name, I think you should be good to go.

This is an issue and initially this seems to be the only culprit, if the issue still persists, please comment I will update my answer accordingly.

UPDATE 1: If you are able to fetch the Attachment records using inner query, you can access them like below:

<aura:attribute name="case" type="Case"/> <!-- Save the whole case record here -->

{!v.case.Attachments[0].Name}
8
  • Still not resolved :(
    – Nebbyyy
    Commented Feb 1, 2017 at 13:32
  • Please see your browser console for any JS errors. Also confirm that you are getting the recordId assigned to the caseId attribute properly and you have the value present before making the apex function call. Commented Feb 1, 2017 at 13:43
  • 1
    The id is being parsed correctly as thats just a snippit of the relevant code, all the other information from the case is parsed in fine and there are no errors. What about if i tried something like Select id, Atrium_Subject__c, Atrium_AmexSubject__c, Status, Contact.Name, ContactId, CreatedDate, Message_Number__c, LastModifiedDate, Description__c, (SELECT id, Name From Attachments) From Case Where id=:caseId But not sure how i would reference the attachments name in the front end
    – Nebbyyy
    Commented Feb 1, 2017 at 14:01
  • Updated my answer with it. Commented Feb 1, 2017 at 14:11
  • 1
    Thank god its outputting the name, god knows why it wouldn't work the other way :/, is there a quick way to iterate through the outputted names of an inner query until all attachment names have been outputted?
    – Nebbyyy
    Commented Feb 1, 2017 at 14:16

You must log in to answer this question.

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