Skip to main content

Hello,

 

I tried creating a server-side action and came across a weird issue. I tried checking online for solutions and am still stuck. Could you help me?

 

Lightning Component: TunaFishCheck.cmp

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickActionWithoutHeader" controller="SeaFood" access="global">

<aura:attribute name="tuna" type="Boolean" default="false"/>

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

<aura:if isTrue="{!tuna}">

<div>true</div>

<aura:set attribute="else">

<div>false</div>

</aura:set>

</aura:if>

</aura:component>

 

function

tunaCheck: function (cmp){

console.log('Its inside');

var tuna= cmp.get("c.doAction");

console.log('Check: ' + tuna);

action.setCallback(this, function(response){

var stateF = response.getReturnValue();

alert("Check: " + stateF);

if (stateF === 'SUCCESS'){

component.set("{!v.tuna}", response.getReturnValue());

} else {

console.log('Unsuccessful return value');

}

});

$A.enqueueAction(tuna);

}

 

Apex Component

public with sharing class SeaFood {

ApexPages.StandardController sc;

public SeaFood(ApexPages.StandardController controll){

this.sc = controll;

}

@AuraEnabled

public static Boolean doAction(){

PageReference refPage;

Boolean fish = fishCheck()();

if (fish){

return true;

} else if (!fish){

return false;

}

return fish;

}

@AuraEnabled

Public static Boolean fishCheck(){

//censored functionality code

return true;

}

 

Note: while running,

console log shows: 

Its Inside

Check:

SecureAction: [object Object]{ key: {"namespace":"c"}

UI:

error while creating componenet for lightning component quick action [Action failed c:TunaFishCheck$controller$tunaCheck [action is not defined]]

 

Noticed that console.log('Check: ' + tuna); doesn't have a value

How can I fix these issues?

 

#Salesforce Developer #Custom Actions #Apex Class #Aura Lightning Components #Lightning Component #Lightning Flow

5 risposte
  1. 29 ott 2021, 03:14

    @Suraj Tripathi I able to add the value but there seems to be a bug. The code does not do initialization and goes directly to <aura:set attribute="else"> statement. If I remove the else statement, then only it goes into <aura:if>. Any suggestions?

     

    Note: I have the initialization command in the code

    <aura:attribute name="tuna" type="Boolean" default=""/>

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

0/9000