Background: I'm adding hard deletes to the Salesforce destination in StreamSets Data Collector. Adding the ability to do hard deletes via the Bulk API is trivial - just specify
hardDelete instead of
delete as the operation for the job. Where I'm hitting a problem is in testing that a hard delete did, in fact, happen, rather than a soft delete.
As has been discussed in answers to questions such as The netherworld of deleted records not in recycle bin, explicitly hard-deleted records, and records emptied out of the recycle bin, still show up in queries for deleted records alongside the contents of the recycle bin. The final section of the article Recover records and data in Salesforce explains the record deletion deathcycle that causes this behavior - the period of time between records being marked for deletion and actually deleted.
And so we come to the question: is there a way to retrieve the contents of the recycle bin via API (I'm not aware of one!), or a way to determine whether a given record is in the recycle bin or not, short of trying to undelete the record.
I have verified that, as expected, I can undelete a soft-deleted record, and that trying to delete a hard-deleted record located via a SOQL query in Apex does indeed fail:
Account a = [SELECT Id, Name FROM Account WHERE Name = 'deleteme' ALL ROWS]; System.debug(a); undelete a;
Trying the above after hard-deleting the Account 'deleteme' gives:
System.DmlException: Undelete failed. First exception on row 0 with id 0011R00002iWH24QAG; first error: UNDELETE_FAILED, Entity is not in the recycle bin: 
I can try to undelete the record and test for the exceptions, but I'd like a more... elegant approach.