0

I have an Apex Method named "ShowOutput" which is returning either true or false.

How can I evaluate the response is true or not in Aura controller.

I tried below code

var action = component.get('c.showOutput');        
    action.setCallback(this, function(response) {
        var state = response.getState();
        if(state === 'SUCCESS') {
            component.set('v.searchHub', 'health-source');
        } else {
            component.set('v.source', 'health-source1');
        }
0

1 Answer 1

0

getReturnValue()

Gets the return value of an Apex action. An Apex action can return any object containing serializable JSON data.

check this documentation for more methods on reponse Obejct

you can use response.getReturnValue() to see if you apex class returned True or false considering your apex class returns Boolean value

Example

var action = component.get('c.showOutput');
action.setCallback(this, function(response) {
    var state = response.getState();
    if(state === 'SUCCESS') {
        var result = response.getReturnValue(); //value returned from your apex class
        if(result) {
            component.set('v.searchHub', 'health-source');
        } else {
            component.set('v.source', 'health-source1');
        }
    } else {
        console.log('Error: ' + response.getError());
    }
});
$A.enqueueAction(action);
1
  • 1
    thanks Aman, it worked Mar 23 at 11:12

You must log in to answer this question.

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