function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
prasanth sfdcprasanth sfdc 

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;
     }
    
}

 
Best Answer chosen by prasanth sfdc
sfdcMonkey.comsfdcMonkey.com
hi
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
({
	myAction : function(component, event, helper) {
        // var for judgment on if statement.
           var ifvalue;
        
        var textval = component.find("name").get("v.value");
        console.log(textval);

        var textval2 = component.find("name2").get("v.value");
        
        if(textval == textval2)
            ifvalue = "true";
       
        console.log('The ifvalue is : '+ ifvalue);
        component.set("v.ifvalue",ifvalue);
	},
    
    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();
            alert('piyush code check state ==>' + state);
            if(state == 'SUCCESS')
            {    
            
            
                    console.log("The state is SUCCESS");
                     component.set("v.errormeg",a.getReturnValue());
            }
            else
            {
                console.log("The state is false");
            }
           
        });
    $A.enqueueAction(action);
  }
})

apex class
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){
                   List<contact> cc = new List<contact>(); 
                    cc.add(con);
                  	insert cc;	
         		}
            }
         catch(exception er1){
             errormsg=string.valueOf(er1);
             system.debug('inside the catch method');
         }
         system.debug('The error message value is : '+errormsg);
         return errormsg;
     }
    
}

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

prasanth sfdcprasanth sfdc
hi,  The new contact reocrd is inserting but the state is coming as false.   It is going into if(state == false)  statement. 

User-added image

 
prasanth sfdcprasanth sfdc
Sure thanks.

 
<aura:component controller="eventsexampleapexclass">
  <!--  <aura:handler name="init" value="{!this}" action="{!c.myAction}" /> -->
    <aura:attribute name="ifvalue" type="String" />
    // checking the two inputtext values are same or not. 
    <ui:inputtext label="your name" aura:id="name"  />
    <ui:inputtext label="you name again" aura:id="name2" change="{!c.myAction}" />
    
    .....The value of ifvalue is : {!v.ifvalue} .... <br/><br/>
    
    
    <aura:if isTrue="{!v.ifvalue}">
    True
    <aura:set attribute="else">
      False
    </aura:set>
    </aura:if>   <br/><br/>
    
    <h2>The New contact details</h2>
   
    <aura:attribute name="newcontact" type="contact" default="{ 'sobjectType': 'Contact' }"/>
                 
    <aura:attribute name="errormeg" type="string" />
    
    <h2 style="color:red;">{!errormeg}</h2> 
    <ui:inputText aura:id="contactName" 
                 value="{!v.newcontact.LastName}" label="Name"/>
   
    <ui:inputPhone value="{!v.newcontact.Phone}" aura:id="contactPhone" label="Phone"/>
    <ui:inputText value="{!v.newcontact.Department}"  aura:id="contactde" label="Department"/>
    <ui:inputDate value="{!v.newcontact.Birthdate}"  aura:id="contactbd" label="D.O.B" displayDatePicker="true"/>
    <ui:inputText value="{!v.newcontact.Level__c}" aura:id="contactll" label="Level"/>
   
    <br/><br/>
    <ui:button label="insert cont" press="{!c.newcontacts}" />

</aura:component>






({
	myAction : function(component, event, helper) {
        // var for judgment on if statement.
           var ifvalue;
        
        var textval = component.find("name").get("v.value");
        console.log(textval);

        var textval2 = component.find("name2").get("v.value");
        
        if(textval == textval2)
            ifvalue = "true";
       
        console.log('The ifvalue is : '+ ifvalue);
        component.set("v.ifvalue",ifvalue);
	},
    
    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.set("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;
     }
    
}

 
sfdcMonkey.comsfdcMonkey.com
hi
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
({
	myAction : function(component, event, helper) {
        // var for judgment on if statement.
           var ifvalue;
        
        var textval = component.find("name").get("v.value");
        console.log(textval);

        var textval2 = component.find("name2").get("v.value");
        
        if(textval == textval2)
            ifvalue = "true";
       
        console.log('The ifvalue is : '+ ifvalue);
        component.set("v.ifvalue",ifvalue);
	},
    
    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();
            alert('piyush code check state ==>' + state);
            if(state == 'SUCCESS')
            {    
            
            
                    console.log("The state is SUCCESS");
                     component.set("v.errormeg",a.getReturnValue());
            }
            else
            {
                console.log("The state is false");
            }
           
        });
    $A.enqueueAction(action);
  }
})

apex class
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){
                   List<contact> cc = new List<contact>(); 
                    cc.add(con);
                  	insert cc;	
         		}
            }
         catch(exception er1){
             errormsg=string.valueOf(er1);
             system.debug('inside the catch method');
         }
         system.debug('The error message value is : '+errormsg);
         return errormsg;
     }
    
}

let me inform if it helps you
Mark it best answer if it helps you so it make proper solution for others :)
Thanks



 
 
This was selected as the best answer
prasanth sfdcprasanth sfdc
Thank you so much........   
sfdcMonkey.comsfdcMonkey.com
Pleasure
https://dfc-org-production.force.com/forums/ForumsMain?id=9060G000000XdlvQAC
mark above question link  solved if you got your solution :)