You need to sign in to do that
Don't have an account?

callback function state is false
In this code. call back function state is coming as false. Please help.
newcontacts : function(component, event, helper){ var contval = component.get("v.newcontact"); console.log('The con vlaue is ',contval); var action = component.get("c.getlightcons"); action.setParams({ con : contval }); action.setCallback(this,function(a){ //get the response state var state = a.getState(); if(state == true) { console.log("The state is true"); component.get("v.errormeg",a.getReturnValue()); } else { console.log("The state is false"); } }); $A.enqueueAction(action); } }) public class eventsexampleapexclass { @AuraEnabled public static string getlightcons(contact con) { system.debug('inside the The error message value is : '); string errormsg =''; try{ if(con!= null) { insert con; } } catch(exception er1) { errormsg=string.valueOf(er1); system.debug('inside the catch method'); } system.debug('The error message value is : '+errormsg); return errormsg; } }
i find some mistake in your code
1. use (state == 'SUCCESS') insteadOf (state == 'True')
2. you can not insert contact object direct in your apex class use List<contact> cc = new List<contact>();, then add con into new list and insert cc ;
3. use console.log('The con vlaue is '+ contval); insteadOf
console.log('The con vlaue is ',contval);update your code with below code
apex class
let me inform if it helps you
Mark it best answer if it helps you so it make proper solution for others :)
Thanks
All Answers
i find some mistake in your code
1. use (state == 'SUCCESS') insteadOf (state == 'True')
2. you can not insert contact object direct in your apex class use List<contact> cc = new List<contact>();, then add con into new list and insert cc ;
3. use console.log('The con vlaue is '+ contval); insteadOf
console.log('The con vlaue is ',contval);update your code with below code
apex class
let me inform if it helps you
Mark it best answer if it helps you so it make proper solution for others :)
Thanks
https://dfc-org-production.force.com/forums/ForumsMain?id=9060G000000XdlvQAC
mark above question link solved if you got your solution :)