Skip to main content
Hello

I have followed the trailhead "Similar Properties" and get it working ok. But when I then modify it to use a custom object in the underlying APEX, the values in the fields are blank. I know the items are there because it iteraties through ok - but when i read the fields nothing is returned. Here is my APEX code, handler and aura component:

 

public with sharing class CustomerLifeTimeController {

public with sharing class Itinerary{

String ItineraryRef;

}

@AuraEnabled

public static List<Object> getRelatedItineraries (Id recordId) {

List<Itinerary> itins = new List<Itinerary>();

Itinerary itin = new Itinerary();

itin.ItineraryRef = 'Itinerary 1';

itins.Add(itin);

return itins;

}

}

 

({

doInit : function(component, event, helper) {

var action = component.get("c.getRelatedItineraries");

action.setParams({

recordId: component.get("v.recordId")

});

action.setCallback(this, function(response){

var relatedItins = response.getReturnValue();

component.set("v.relatedItineraries", relatedItins);

});

$A.enqueueAction(action);

}

}

)

 

<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId" controller="CustomerLifeTimeController">

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

<aura:attribute name="relatedItineraries" type="Object" />

<aura:attribute name="opportunity" type="Object" />

<aura:attribute name="remoteRecordId" type="Id" />

<aura:attribute name="showDialog" type="String" default="false" />

<force:recordData aura:id="relatedPropertyService"

recordId="{!v.recordId}"

targetRecord="{!v.opportunity}"

recordUpdated="{!c.doInit}"

layoutType="FULL" />

<lightning:card iconName="custom:custom84" title="Related Itineraries">

Info<br/>

<aura:iteration items="{!v.relatedItineraries}" var="item" indexVar="i">

Item : {!item.Itinerary}

</aura:iteration>

</lightning:card>

</aura:component>

Any help gratefully received! Note that if i change the APEX to return a list of Opportunities (and use a read field name in the aura component) it works fine, so I'm fairly sure the javaScript is wired up ok - I'm just misunderstanding someelse somewhere!

Thanks

 
1 respuesta
  1. 30 abr 2018, 7:32
    Hi Both

    I have figured out the issue - and it was actually neithrer of the above; Hemant_Soni - you can't change to sObject because you can't convert Itinerary object to that. Alain - the Lightning Data Service works with custom objects - and the init is already wired up (proven because Aura Iteration was working ok).

    The actual problem was that in my custom object, the property ItineraryRef was not declared as public, and did not have the @AuraEnabled attribute. As soon as I did this, data appears ok!

    for example it needed to be this:

     

    public with sharing class Itinerary{

    @AuraEnabled

    public String ItineraryRef;

    }