• Kania @Daydream
  • NEWBIE
  • 5 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
I am calling a server side action from a Lightning Component. When an error occurs I am trying to log them in a custom object using an @future method and then throwing an AuraHandledException so the component can display the message. It seems like this won't work with AuraHandledException since it causes a Script-thrown execption in the logs which causes the @future method not to execute. Am I doing something wrong or is there another way to accomplish it?

Here is documentation I am referencing:

Error Handling Best Practices for Lightning and Apex:
https://developer.salesforce.com/blogs/2017/09/error-handling-best-practices-lightning-apex.html

An Introduction to Exception Handling:
https://developer.salesforce.com/page/An_Introduction_to_Exception_Handling
 
@auraEnabled
public static void getSomething(){
    
    try{
        //Do Something here 
        
    }catch(exception e){
        
        //@future - log error in custom object
        futureCreateErrorLog.createErrorRecord(e.getMessage());
        
        throw new AuraHandledException('Error message to display in component');
    }
    
}

User-added image
I am calling a server side action from a Lightning Component. When an error occurs I am trying to log them in a custom object using an @future method and then throwing an AuraHandledException so the component can display the message. It seems like this won't work with AuraHandledException since it causes a Script-thrown execption in the logs which causes the @future method not to execute. Am I doing something wrong or is there another way to accomplish it?

Here is documentation I am referencing:

Error Handling Best Practices for Lightning and Apex:
https://developer.salesforce.com/blogs/2017/09/error-handling-best-practices-lightning-apex.html

An Introduction to Exception Handling:
https://developer.salesforce.com/page/An_Introduction_to_Exception_Handling
 
@auraEnabled
public static void getSomething(){
    
    try{
        //Do Something here 
        
    }catch(exception e){
        
        //@future - log error in custom object
        futureCreateErrorLog.createErrorRecord(e.getMessage());
        
        throw new AuraHandledException('Error message to display in component');
    }
    
}

User-added image
I am calling a server side action from a Lightning Component. When an error occurs I am trying to log them in a custom object using an @future method and then throwing an AuraHandledException so the component can display the message. It seems like this won't work with AuraHandledException since it causes a Script-thrown execption in the logs which causes the @future method not to execute. Am I doing something wrong or is there another way to accomplish it?

Here is documentation I am referencing:

Error Handling Best Practices for Lightning and Apex:
https://developer.salesforce.com/blogs/2017/09/error-handling-best-practices-lightning-apex.html

An Introduction to Exception Handling:
https://developer.salesforce.com/page/An_Introduction_to_Exception_Handling
 
@auraEnabled
public static void getSomething(){
    
    try{
        //Do Something here 
        
    }catch(exception e){
        
        //@future - log error in custom object
        futureCreateErrorLog.createErrorRecord(e.getMessage());
        
        throw new AuraHandledException('Error message to display in component');
    }
    
}

User-added image