Transaction is not rolled back when calling remote action method via JavaScript remoting even if exception is thrown from the method
Last updated 2022-02-10 ·Reference W-2353408 ·Reported By 48 users
Summary
Transaction is not rolled back when calling remote action method via JavaScript remoting even if exception is thrown from the method.
Repro
1. Create the following Apex class
public with sharing class XX_RollbackTest {
@RemoteAction
public static void updateAndThrowException() {
Account newAccount = new Account(Name='RollbackTestException');
insert newAccount;
throw new RollbackTestException('Update Failed');
}
public class RollbackTestException extends Exception {
}
}
2. Create the following Visualforce page
<apex:page controller="XX_RollbackTest">
<script type="text/javascript">
function updateError() {
Visualforce.remoting.Manager.invokeAction(
'{!$RemoteAction.XX_RollbackTest.updateAndThrowException}',
function(result, event) {
console.log(result);
console.log(event);
},
{escape: true}
);
}
</script>
<apex:form >
<apex:commandButton onclick="updateError();return false;" value="UpdateAndThrowExceptionRemoteScript" id="UpdateAndThrowExceptionRemoteScript"/>
</apex:form>
</apex:page>
3. Access to the above Visualforce page
4. Click “UpdateAndThrowExceptionRemoteScript” button
5. Check Accounts
You will see an account named "RollbackTestException" is created. This is unexpected behavior.
Workaround
Use savepoint in remote action method and rollback explicitly in error status
Reported By (48)
























Is it Fixed?
Any unreleased services, features, statuses, or dates referenced in this or other public statements are not currently available and may not be delivered on time or at all. Customers who purchase our services should make their purchase decisions based upon features that are currently available.