1

I am trying to show the toast on the screen after the field is updated using the lightning component the Controller looks like below

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();


            var toastEvent = $A.get("e.force:showToast");
            toastEvent.setParams({
                title: "Success!",
                message: "Congrats, it works!",
                type: "success"
            });
            toastEvent.fire();          

        } else { /* show an error here */ }

      }));
  }
  }})

Component

<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"
                    mode="EDIT"
                    recordUpdated="{!c.recordLoaded}" />
</aura:component>

Everything else is working but I cannot see the Toast on the screen after it updated the field

2
  • try after removing $A.get("e.force:refreshView").fire();
    – User6670
    Apr 2, 2020 at 19:25
  • Awesome that worked. Can we call the lightning component from the button as a URL?
    – user81642
    Apr 2, 2020 at 20:12

1 Answer 1

0

Try removing

$A.get("e.force:refreshView").fire(); 

and then fire toast and no i dont think you can launch component from button though you can open visual force page from button where you can call your component from there here is the documentation on how you can do that https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/components_visualforce.htm

You must log in to answer this question.

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