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
Athira VenugopalAthira Venugopal 

Issue in server side Apex controller

I am working on Lightning aura components. The problem is in my servide side apex controller, its not returning the expected result. Te result is [Object,Object]

BoatSearchResults.cmp

<aura:component controller = "BoatSearchResults" implements="flexipage:availableForAllPageTypes" access="global" >
   <aura:attribute name="boats" type="Boat__c[]"/>

     <lightning:layout multipleRows="true">
           <lightning:button variant="brand" label="Search" onclick="{! c.searchBoat }" aura:id="SearchButton" />
        <aura:if isTrue="{!v.boats.length > 0}">
            <aura:iteration items="{!v.boats}" var="bot">
                <lightning:layoutItem  size="3" flexibility="grow" class="slds-m-around_small">
                    <c:BoatTile boat="{!bot}" />
                </lightning:layoutItem>
            </aura:iteration>
            <aura:set attribute="else">
                <lightning:layoutItem class="slds-align_absolute-center" flexibility="auto" padding="around-small">
                    <ui:outputText value="No boats found" />
                </lightning:layoutItem>
            </aura:set>
        </aura:if>
    </lightning:layout>
  
</aura:component>

js file

({
       searchBoat : function(component, event) {
            let action = component.get("c.getBoats");
            action.setCallback(this, function(response){
            let state = response.getState();
            if (state === "SUCCESS") {
                console.log('TEST ' + response.getReturnValue());//  this ouput is [Object, Object]
                component.set("v.boats", response.getReturnValue());
            }
        });
        $A.enqueueAction(action);
       },
    
   
})

BoatSearchResults.apxc

public with sharing class BoatSearchResults {
    @AuraEnabled
    public static List<Boat__c> getBoats() {
     return [select id,Name,BoatType__c,Contact__c,Picture__c from Boat__c];
    
    }
  
}


BoatTile.cmp

<aura:component implements="flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global" >
    <aura:attribute name="boat" type="Boat__c"/>

    <lightning:button class="tile">
        <!-- Image -->
        <div style="{!'background-image: url(\'' + v.boat.Picture__c + '\')'}" class="innertile">
            <div class="lower-third">
                <h1 class="slds-truncate">{!v.boat.Name}</h1>
            </div>
        </div>
    </lightning:button>
</aura:component>


 
Danish HodaDanish Hoda

Try 
console.log(JSON.stringify(response.getReturnValue())); to check the result you are getting

sachinarorasfsachinarorasf
Hi Athira,

This is not the issue with the server-side apex controller.

console.log('TEST ' + response.getReturnValue());//  this ouput is [Object, Object]

Here you are trying to concatenate object and string.

To show output, simply stringify the return value like:

console.log('TEST'+JSON.stringify(response.getReturnValue()));

I hope you find the above solution helpful. If it does, please mark it as Best Answer to help others too.

Thanks and Regards,
Sachin Arora
www.sachinsf.com
Athira VenugopalAthira Venugopal
Thanks Danish and Sachin. Now I am able to check the result. But why my BoatTile.cmp is not getting rendered On selecting the boattype, I need to show the images of boats in BoatTile.cmp
Athira VenugopalAthira Venugopal
it is showing the boats length, I printed it inside 'Matching Boats'