1

Trying to create a Lightning button to close a case and I am getting this error

Uncaught Unable to find action 'getCaseStatusPickList' on the controller of c:Button Callback failed: apex://closeCaseApex/ACTION$getCase

After adding in the getCaseStatusPickList method I am getting another error:

Uncaught Assertion Failed!: run() cannot be called on a server action. Use $A.enqueueAction() instead. : false

Below is the updated code

Button.cmp

<aura:component controller="closeCaseApex" implements="flexipage:availableForAllPageTypes,force:hasRecordId" access="global">
<aura:attribute name="record" type="Case"/>
<aura:attribute name="caseStatus" type="String"/>
<aura:attribute name="caseId" type="String" default="{!v.recordId}"/>

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

<button class="slds-button slds-button--neutral newsbutton" style="float:right"  onclick="{!c.closeCases}">Close Case</button>

closeCaseApex.apxc

public class closeCaseApex{
@AuraEnabled
public static Case getCase(Id caseId){
    return ([Select Id, Status From Case Where id=:caseId]);
}
@AuraEnabled
public static Case closeCases(Case caseA){
   update caseA;
   return caseA;
}
@AuraEnabled
public static List<Case> getCaseStatusPickList(String caseId){
   return([Select Status From Case]);
}}

ButtonHelper.js

({
getStatusPickListValue : function(component) {

    var action = component.get("c.getCaseStatusPickList");
    action.setCallback(this, function(response) {
        var state = response.getState();
        var hasImg = false;
        if (component.isValid() && state === "SUCCESS") {

            var statusPickList = response.getReturnValue();
            component.set("v.lstCaseStatus", statusPickList);

            console.log('status picklist ::', component.get("v.lstCaseStatus"));
        }
    });
    $A.enqueueAction(action);

},})

ButtonController.js

({
doInit : function(component, event, helper) {
component.set("v.isError", false)
component.set("v.showEditView", false);
component.set("v.errorMsg", "");

var action = component.get("c.getCase");
action.setParams({
    caseId : component.get("v.caseId")
});

action.setCallback(this, function(a) {
    if (a.getState() === "SUCCESS") {
        component.set("v.record", a.getReturnValue());
        helper.getStatusPickListValue(component);
    }
});

$A.enqueueAction(action);
},

closeCase : function (component, event, helper) {
var action = component.get("c.closeCases");
var Status = component.get("v.record.Status") //get value of field
//console.log("Status: " Status);
//action.setParams({Status : Closed});
var caseId = component.get("v.record").Id;
action.setParams({caseA: {Id: caseId, Status : "Closed"}});
$A.enqueueAction(action);
},
})
  • 1
    where is the backend method getCaseStatusPickList ? – Mohith Shrivastava Jan 3 at 0:39
  • I need another method in my apex class for example public static Case getCaseStatus(){} which queries for the status of the case. Is that correct? – user3517221 Jan 3 at 0:48
0

You need to create a method called "getCaseStatusPickList" in your Apex Class. I recommend you to check your function names at ButtonController.js because you wrote "closeCase" but you are calling for "closeCases" at Button.cmp

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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