We have an integration that is loading SalesOrders daily into Salesforce. We have created a BeforeInsert Trigger which removes all SalesOrders Created prior to today so that only the currently loaded Orders are visible daily. For the External Id to work correctly the BeforeInsert Trigger has to remove the deleted SalesOrders from the recycle bin.
The emptyRecycleBin code is causing an Apex script exception:
Apex script unhandled trigger exception by user/organization: 00590000000emMO/00D90000000avvb
InsertSalesOrder: execution of BeforeInsert
caused by: [url removed, login to view]: EXCEEDED_ID_LIMIT: emptyRecycleBin id limit reached: 200
[url removed, login to view]: line 11, column 9
We require a modification to the [url removed, login to view] (attached) which deletes all SalesOrder where createddate < today and then deletes these records from the recycle bin.
The number of SalesOrders loaded may be greater than 200 but will not be more than 20,000
A suitable UnitTest also needs to be added to the trigger.