You need to sign in to do that
Don't have an account?
Kania @Daydream
AuraHandledException and Logging Error
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
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'); } }
Here is my usage of that log object
Thanks
Pramodh
allaboutlightning.com
and then
The way to create a custom error log record with AuraHandledException.
I recommend "No 4" method.
1. use Queueable Interface
2. Publish error topics with "Plattform Event", and subscribe to topics with "Process Builder"
3. Do not use "AuraHandledException" when catching Exception,
return a custom wrapper class and display the error message in LightningComponentController.js.
4. Use "AuraHandledException" and The response of state will be "ERROR" In LightningComponentController.js,
fire cusom error event and inserts custom object log records.
I tried to use the "No.1" and JobId was created in System.debug, but it got rolled back.
The method of "No.2" is under trial and no result has come out,
but I guess it is probably rolled back.
The method of "No 3" occures time and effort,
it is expected that an error log will be created unless throwing Exception at the last processing.