Find your content:

Search form

You are here

How can an object with an ID disapear?

 
Share

I have an error logging object that stores errors. In most cases, when I call my method to create a new Error Log record, it properly creates and inserts the record. When I call the error logging method from an @future method, it does not persist.

I have a System.debug statement before and after the Insert is called and the statement after the Insert shows that the object has an ID. The FutureHandler debug logs end shortly after the Insert is confirmed and the object is not deleted. When I look for the object by the ID (both in the Developer Console Query Editor and in the actual Salesforce UI), the record is nowhere to be found.

How can I stop these records from disappearing?


Attribution to: UserIsStuck

Possible Suggestion/Solution #1

Here's a relevant example to catch exception and save to the responding object. It should work.

Ref: https://wiki.developerforce.com/page/An_Introduction_to_Exception_Handling

Logging in a custom object If you get enough emails already, another option would be to use a future method to write a custom object that could catch the error details. Your try-catch would look something like this:

try{
     throw new MyException('something bad happened!');
} catch (MyException e){
     ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.FATAL,'my error msg');
     futureCreateErrorLog.createErrorRecord(e.getMessage());
}
Your future class would look something like this.
global class futureCreateErrorLog {
     @future
     public static void createErrorRecord(string exceptionMessage){
         myErrorObj__c newErrorRecord = new myErrorObj__c();
         newErrorRecord.details__c = exceptionMessage;
         Database.insert(newErrorRecord,false);
     }
}

Attribution to: Cray Kao
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/32209

My Block Status

My Block Content