+ Start a Discussion
Ravi NarayananRavi Narayanan 

Rollback for Future CallOuts in Salesforce- Urgent Help Required !!

Hi Guys,

I have an integration Class where i am having 5 future Methods.

The Requirement is to insert 50,000 records that we are receiving from another ERP.

So due to Governer Limits, i am using Future methods for seperating transaction and inserting 10,000 records in one future method.

My Question is, Suppose if soome error occurs during this Insert Operation,i want to rollBack all the records inserted from this code. 

Suppose if error occurs at 30001 record, all the previously inserted 30,000 records should be rolledback.

Please can someone help me with this.  i am not sure if i can use Savepoint as it is Future Calls and will be a separate Transaction.Its a very urgent issue.

Balaji Chowdary GarapatiBalaji Chowdary Garapati
@Ravi Narayanan:

  I have a suggestion for you., instead of doing 5 callouts, do one callout, assume you received 50K records, loop records through, break it down to multiples of 10k and insert them.

I believe it is not possible to save a savepoint until the complete of 5 future annotated callouts, as they run independently of each other and wont return any result back.
If you still need to able to delete the records, create an other object which stores the ids of the record you inserted and transaction details, which if in case of any error, delete all those records by fetching them from the object. Once you think, your logic is fully completed(5 future methods execution is complete, since you know that count of records will be 50K for sure it is the indication) just truncate  the object, so your space will be saved.

Hope this helps:

Thanks,
Balaji
Ravi NarayananRavi Narayanan
Thanks a lot Balaji for your answer :)