0

I am trying to understand how I can handle response from the Apex Class in to the lightning component Controller. The Apex Class is like below where I am trying to check the Account Id of the Case and show a toast through lightning component

public class updateCaseRecord {    
  @AuraEnabled
    public static String passCase(String caseId){
        List<Case> case_recs = [SELECT id,AccountId,Status,Subject from Case WHERE Id = :caseId];
        String returnString;
        for (Case rec : case_recs)
        {
            if (rec.AccountId == '001U000001OgQ0OIAV')
            {
                returnString = 'Assign an actual account to the case.';
            }
        }
        //update case_recs;      
        return returnString;
    }    
}

My lightning component is like below

<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId" access="global"  controller="updateCaseRecord">
    <aura:attribute name="updateCase" type="Case" default="{'sobjectType':'Case'}"/>
    <lightning:button variant="brand" label="Pass To CS" onclick="{!c.passCaseToCS}"  />
</aura:component>

Lightning Controller

({    
   passCaseToCS : function(c, e, h) {
    h.passCaseToCS_helper(c,e,h);
    }      
})

Helper

passCaseToCS_helper: function(c,e,h) {
    var set_action = c.get("c.passCase");
    set_action.setParams({caseId: c.get('v.recordId')});
    set_action.setCallback(this, result => {
        $A.get("e.force:showToast")
        .setParams({
        type: 'error',
        message: result.returnString,
        mode: 'pester'
    })fire();
    $A.get("e.force:refreshView").fire();
});
$A.enqueueAction(set_action);       
}})

But here I am getting error like Failed to save UpdateCaseCompHelper.js: ESLINT_ERROR: {c:UpdateCaseComp - HELPER} line:col [68:7] --> Parsing error: Unexpected token fire : Source

1

You missed a period to access the function.

}).fire();
2
  • Thanks. It did fix the error but I cannot the toast to be displayed am I missing something here
    – user81642
    Apr 7 '20 at 20:32
  • @user81642 I don't know. Everything appears to be in order. Are you using this component in a Lightning App? If so, you can't use toast notifications, as they only work in Lightning.
    – sfdcfox
    Apr 7 '20 at 22:45

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.