I'm learning Lightning and in the process I'm creating a simple component that would take Name and Description of an Account and insert the same into the database and would also give a Success Message on completion. Following is the code I've written but I'm getting "Callback Failed" error in console.

P.S - My toast part seems not to be working, i've commented all the lines concerned with it then code is running fine. Can someone help me what wrong I'm doing here?

EDIT: I've created a standanlone app using app builder to run this on lightning experience but i'm getting this error message which I'm not able to understand. Uncaught Error in $A.getCallback() [toastEvent is not defined]


<aura:component controller="AccountCreate" implements="force:appHostable">
<aura:attribute name="account" type="Account" default="{'sobjectType':'Account',
<ui:inputText label="Account Name" value="{!v.account.Name}"/>
<ui:inputText label="Description" value="{!v.account.Description}"/>
<ui:button label="create" press="{!c.createAccount}"/>

JS Controller

createAccount : function(component, event, helper) {
    var action = component.get("c.createNewAccount");
    var account = component.get("v.account");
        var state = response.getState();
        var toastEvent = $A.get("e.force:showToast");
        if(component.isValid() && state === "SUCCESS"){
                "title": "Success!",
                "message": "The record has been created successfully."


Apex Controller

public with sharing class AccountCreate {
public static void createNewAccount(Account acc){
    upsert acc;
  • 1
    Check the apex debug logs. What do they say. Or what does response.getError()[0].message; output in the callback
    – Eric
    Commented Feb 20, 2017 at 13:57
  • 1
    Make sure you running in lightning Experiance.Toast event is handled by the one.app container. It’s supported in Lightning Experience and Salesforce1 only.
    – vignesh
    Commented Feb 20, 2017 at 14:36
  • @Eric thanks! Problem was on my js code on case sensitivity. Still trying to figure out why I'm not getting any toast message.
    – Sagnik
    Commented Feb 20, 2017 at 16:09
  • I'm running this by the preview of the Lightning Application i created. Am I doing any wrong there? Getting the following error: This page has an error. You might just need to refresh it. Error in $A.getCallback() [toastEvent is not defined] Callback failed: apex://AccountCreate/ACTION$createNewAccount Failing descriptor: {markup://c:createAccount}
    – Sagnik
    Commented Feb 20, 2017 at 16:12

3 Answers 3


As pointed out by Vignesh Toast Event would run only on Lightning Experience/SF1 I created a SPA using Lightning App Builder with the above component with some minor modification like "flexipage:availableForAllPageTypes" on the component so that it can be used in App Builder. Another mistake I did was regarding case sensitivity of sobjectType . It'was previously sObjectType and so i was getting error. Rest of the code works fine!


The event "e.force:showToast" works in one.app container only.Hence you need to drag and drop this custom lightning component in the lightning app builder post which you can use it.Please refer to below documentation stating the limitation and details of this event



I think the issue is with your upsert statement. Not sure why you are using upsert and it should be Insert. With upsert, you need to specify an External Id field OR salesforce excepts ID which you don't have in this case.

You must log in to answer this question.

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