You need to sign in to do that
Don't have an account?
Avinash Janardhanan
Callout within a transaction
Hi,
I have a requirement, where I need to create a record in Salesforce. Get the ID of the record which got created and then make a webservice call passing this id as one of the parameter. If the webservice call fails, I need to rollback the whole transaction. Is this possible to do?
I tried using Savepoint, but I get the error you have uncommited transactions when I do the callout. Is there a workaround?
Some forums suggested using @future notations, but I need to rollback my DML operation if the callout fails, so can't make it async.
Any suggestions will be appreciated.
I have a requirement, where I need to create a record in Salesforce. Get the ID of the record which got created and then make a webservice call passing this id as one of the parameter. If the webservice call fails, I need to rollback the whole transaction. Is this possible to do?
I tried using Savepoint, but I get the error you have uncommited transactions when I do the callout. Is there a workaround?
Some forums suggested using @future notations, but I need to rollback my DML operation if the callout fails, so can't make it async.
Any suggestions will be appreciated.
Anyways, Do a soft delete first such that these records don't show up in your views/reports and then Delete records using options like MassDelete.
Looks like you are calling out with out a future context, in other words you are performing this from a controller of a page correct?
If you are using it from a controller, you can make use of onComplete property of command button or commandlink or actionfunction tag from which the method is invoked
For eg.,
Page:
<apex:commandButton action="{!someaction of yours}" value="Verify" onComplete="sendCallout();" />
<apex:actionFunction name="sendcallout" action="{!sendactualcallout}" />
Controller:
public static pagereference someactionofyours(){
//capture a savepoint before saving the record in a static variable context
//insert record here and save the id in a variable that has scope for entire class
}
public pageReference sendactualcallout(){
//send you callout, based on result, rollback or leave it
}
If it is not a too complex other than pure insert and delete operation, i would suggest you to insert a record once the transaction is complete because you are deleting the record anyway on failed transaction, you can use save point if there is complex functionality around the object in which you are trying to insert a record(multiple triggers that modified other records data)!
Hope it helps.,
Thanks,
Balaji
I will try out your suggestion Balaji.