0

I am trying to call the lightning Components from the Quick Action to change the status of Case to Closed on click of a button.

Components

<aura:component implements="force:hasRecordId,force:lightningQuickActionWithoutHeader">
  <aura:attribute name="record" type="Case" default="{ 'sobjectType': 'Case' }" />
  <aura:attribute name="complete" type="Boolean" default="false" />
  <force:recordData recordId="{!v.recordId}"
                    fields="['CaseNumber','Status']"
                    targetFields="{!v.record}"
                    aura:id="recordData"
                    recordUpdated="{!c.recordLoaded}" />
</aura:component>

Controller

({ 
  recordLoaded: function(component, event, helper) {
    var caseRecord = component.get("v.record"),
      recordData = component.find("recordData");
      
      caseRecord.Status = 'Closed';
      
      if(!component.get("v.complete")) { // Avoid infinite loop
      component.set("v.complete", true);
      component.set("v.record", caseRecord);
      recordData.saveRecord($A.getCallback(function(result) {
        if(result.state === "SUCCESS" || result.state === "DRAFT") {
          $A.get("e.force:closeQuickAction").fire();
          $A.get("e.force:refreshView").fire();
        } else { /* show an error here */ }
      }));
  }
  }})

But when I click on the Quick Action it throws error like

enter image description here

Not sure what I am missing here, any help is greatly appreciated

1

You also have to set mode="EDIT" for that like this

<force:recordData recordId="{!v.recordId}"
                    fields="['CaseNumber','Status']"
                    targetFields="{!v.record}"
                    aura:id="recordData"
                    mode="EDIT"
                    recordUpdated="{!c.recordLoaded}" />
| improve this answer | |

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.