0

currently I’ve been following the aura components module in trailhead, with the main variation being that I'm using the Opportunity object, and I’ve run into a road block. For some reason when I try to save my Opportunity objects to my salesforce org, the return state I get in my helper file is ERROR.

So my main question is: is this a problem in my code or a problem with my org?

From what I understand the relevant files where the problem may lie is with my JS client controller and helper or my Apex server controller. Here is the code for all three.

Client Controller

({
    myAction : function(component, event, helper) 
    { 
        console.log('in myAction');
        var ValidDon = component.find('donationform',true); 
        
        if(ValidDon)
        {
        var newDon = component.get("v.Donation_Fields")  
        console.log("Create Donation: " + JSON.stringify(newDon)); 
            
            console.log('entering helper');
            helper.MakeDon(component,newDon);         }
    },
    
    Beginning:function(component,event,helper)
    {
        console.log('in Beginning');
    var action = component.get("c.GetDonations"); 
    
   
    action.setCallback(this,function(response){ var state =  response.getState(); 
        if(state == "SUCCESS") 
    {
    component.set("v.expenses",response.getReturnValue()); } else
 {
 console.log("Failed with state " + state);
 }

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

})

Helper

({
    MakeDon : function(component,donation) 
    {
        console.log('entered helper');
               
         var action = component.get("c.saveDonation");
        console.log('got saveDonation');
        action.setParams({"Donation":donation});
               
        action.setCallback(this,function(response){ 
            var state = response.getState();
            if(state == "SUCCESS")
            {
                console.log('was a success');
                 var donations =  component.get("v.Donations");
                expenses.push(response.getReturnValue());
                component.set("v.Donations",donations);
            }else{
                console.log('it  somehow failed! state is: ' + state);
            }
        });
        console.log('enquing action');
        $A.enqueueAction(action);
        
        
        
    },
})

Server Controller

public with sharing class Apex_Controller {
    @AuraEnabled
    
    public static List<Opportunity> GetDonations()
    {
        
        System.debug('In GetDonations');
        return [SELECT Id,Name,Amount,StageName,CloseDate,AccountId FROM Opportunity];
    }
    
    
    @AuraEnabled
    public static Opportunity  saveDonation( Opportunity Donation)
       
    {
        System.debug('In saveDonation');
      
       upsert Donation;
        return Donation;

       
        
    }

}

Appreciate your help.

  • You should look at the debug logs to see if there is some problem with server side, and also check the browser developer console to see if error is at client side. – Raul Aug 11 at 17:27
0

This could be for a variety of reasons, such as validation rule failing, missing required fields, etc. I do not see anything inherently wrong with your code. Check the results of the error message to find out more:

if(state === 'SUCCESS') {
   ...
} else {
   alert(response.getError()[0].message);
}
| improve this answer | |
  • I did this and I got the message: "Unable to read SObject" . In my component I made sure my attribute used sobjectType correctly, but I'm still getting that error, any ideas? – Apex_rookie Aug 12 at 16:38
  • @Apex_rookie would need to see your Apex as well; I had to make some assumptions about your data when writing this answer. Most importantly, the return type and parameters of the methods would help us in figuring out what went wrong. – sfdcfox Aug 12 at 18:32
  • My Apex is the Server Controller at the bottom with the Class name Apex_Controller. – Apex_rookie Aug 13 at 14:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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