You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If I have code like this, where I perform a DML operation first then try to Rollbar:
upsert someRecord;
Rollbar.init();
Rollbar.log('error', 'API Check Failed');
I then do indeed seeing this error:
17:46:30.0 (610688168)|FATAL_ERROR|System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out
Class.Notifier.send: line 45, column 1
Class.Notifier.send: line 34, column 1
Class.Notifier.log: line 14, column 1
Class.Rollbar.log: line 41, column 1
So one thing I tried is a thin wrapper over Rollbar:
public class RollbarClient {
private static final String ERROR_LEVEL = 'error';
private static final String WARN_LEVEL = 'warning';
@future(callout=true)
public static void error(String message) {
log(ERROR_LEVEL, message);
}
public static HttpResponse errorSync(String message) {
return log(ERROR_LEVEL, message);
}
public static HttpResponse log(String level, String message) {
Rollbar.init();
return Rollbar.log(level, message);
}
}
Using the @future decorators. This works in some cases, but then I found this case:
if(some condition) {
RollbarClient.error('error', 'API Check Failed');
throw new AuraHandledException('Some error');
}
It turns out if you throw in an Apex transaction, all pending work is rolled back, including future methods, so the future methods are never "saved" to be executed later.
So I added an errorSync and warnSync method to this class to use in cases where an exception is thrown in the same transaction.
The text was updated successfully, but these errors were encountered:
Feedback from a user:
The text was updated successfully, but these errors were encountered: