0

I want to fetch records using Aura component but I get the Invalid attribute "name" error in <aura:handler name="init" value="{!this}" action="{!c.myAction}" /> tag.

CMP:

<aura:component controller="myClass" implements="flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,force:lightningQuickAction" access="global">

  <aura:attribute name="recordId" type="Id" />
  <aura:attribute name="previousPatJ" type="List" /> 

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

   <aura:iteration  items="{!v.previousPatJ}" var="patj">
        Journey Name = {!patj.Name} <br/>
   </aura:iteration>

</aura:component>

Class:

public class myClass{
    
    @AuraEnabled
    public static List<myObject> getPreviousJ(Id recordId){
        try {
            List<myObject> oldPatientJ = [SELECT Name FROM myObject 
                                          WHERE Previous_Journey__c = :recordId 
            ];

             return oldPatientJ;
        } catch (Exception e) {
            throw new AuraHandledException(e.getMessage());
        }
    }
}

JS:

({
myAction : function(component, event, helper) 
   {
      var oldPatientJ = component.get("c.getPreviousJ");
      oldPatientJ.setParams
      ({
         recordId: component.get("v.recordId")
      });
      
      oldPatientJ.setCallback(this, function(data) 
      {
         component.set("v.previousPatJ", data.getReturnValue());
      });
      
      $A.enqueueAction(oldPatientJ);
   }

 })

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.