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);
},
})