0

This question already has an answer here:

when i clicked on button after saving record it is showing error message that component need to refresh it. i have already refresh it even cookie cache and history also deleted but not showing success toast message.

     ({
CreateContact : function(component, event, helper) {
    var cont = component.get("v.ConDetails");
    var toastEvent = $A.get("e.force:showToast");
    toastEvent.setParams({
                    "title": "Success!",
                    "message": "Record Save Successfully",
                    "type": "SUCCESS"
                });
    var action = component.get("c.NewCon");
    action.setParams({ "con": cont
    });

    action.setCallback(this, function(a) {
           var state = a.getState();
            if (state === "SUCCESS") {
                toastEvent.fire();

            }
        });
    $A.enqueueAction(action);
}
})

enter image description here

Controller code below

   public class NewContactController {

@AuraEnabled
public static contact NewCon(Contact con){
    if(con != null){
        insert con;
    }
    return con;
  }
}

Component code below

  <aura:component controller="NewContactController" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global" >
<aura:attribute name="ConDetails" type="contact" default="{ 'sobjectType' : 'Contact' }" />

<lightning:card variant="Narrow" title="Contact" iconName="standard:contact"> </lightning:card>
    <div class="slds-p-bottom_large slds-p-left_large" style="width:500px">
        <p class="slds-p-horizontal_small">
            <lightning:input aura:id="confn" value="{!v.ConDetails.FirstName}" label="First Name"/>
        </p>
        <p class="slds-p-horizontal_small">
            <lightning:input aura:id="conln" value="{!v.ConDetails.LastName}" label="Last Name"/>
        </p>
        <p class="slds-p-horizontal_small">
            <lightning:input aura:id="contemail" value="{!v.ConDetails.Email}" label="Email"/>
        </p>
        <p class="slds-p-horizontal_small">
            <lightning:button aura:id="save" type="save" label="Save record" variant="brand" class="slds-m-top_medium" onclick="{!c.CreateContact}" />
        </p>
    </div>

marked as duplicate by sfdcfox, Pranay Jaiswal, David Reed, glls, Raul Nov 22 '18 at 18:00

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • It seems that there is no Apex method called NewCon available in the Controller. Please check the Apex Controller Class. – Saroj Bera Nov 22 '18 at 11:09
  • class is ther and method as well i have added controller code pls check – cloudZigZag Nov 22 '18 at 11:11
  • 1
    Are you firing this from the developer console? if that is the case try to do it via an app or lightning quick action. I think that your toastEvent is undefined because you are trying to fire it from DC. – Carlos Naranjo Nov 22 '18 at 12:19
1

Are you firing this from the developer console? if that is the case try to do it via an app or lightning quick action. I think that your toastEvent is undefined because you are trying to fire it from the Developer Console. –

the solution for this is to fire this component from a app or lightning quick action. You can also drag it to a detail page and verify if it works form there.

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