4

It seems most objects, when deleted, will get their record updated with IsDeleted = true while they stay in the recycle bin until they're purged.

However, we have found some objects just get automatically purged and don't go into a recycle bin. You can include IsDeleted in a SOQL/query against these objects, but there will never be a record where that flag is true.

In terms of replications to SQL tables, this can be difficult to track when you're not dropping and re-building tables and relying on updates and this deleted flag.

Is there an easy way to tell how an object will behave when deleted: setting this flag and staying in the recycle bin vs. being outright purged?

It does seem that individual objects' documentation will not include references to the IsDeleted field which may point to them not using it as 2 examples we've seen below don't list that field

ObjectTerritory2Association

Topic

But, the fact that it can be used in a query on those objects and is listed as a system field under that object makes it difficult to figure this out without manually looking at documentation.

enter image description here

1
  • You could perhaps write a test class that creates 1 record of each object, insert each, delete each, then assert/confirm whether or not it still exists in the recycle bin via an ALL ROWS soql clause. Maybe there’s a better way. Dec 24, 2020 at 15:19

1 Answer 1

3

You can describe an sObject (available in Apex via sObjectType.getdescribe(), REST API describe call, and SOAP API describeSObject()), and you'll see a property called "undeletable." If true, IsDeleted is meaningful and you can retrieve and undelete records from this object.

However, if you're interested in replication, as this question seems to imply, you should use the getDeleted API call (REST, SOAP). This call can get information for up to a month old about records that have been deleted, even if they are purged from the recycle bin before replication occurs, or even if the sObject in question does not allow recovery from the recycle bin (it will always allow you replicate deletions of records). You should use this API if you're replicating data.

Also, see getUpdated if you want to easily replicate updates to records as well. This API even gives you a way to detect "in flight" records so that you never accidentally miss records that would have been missed between two queries (e.g. because they were being inserted/updated in another thread while the call was active).

2
  • This is great, thanks. It seems I get a sObjectType is not replicable for an object like ObjectTerritory2Association. It seems I'd also have to check the isReplicable property as that would preclude the object from that getDeletedAPI call as well and I think we're out of options for those objects. Dec 25, 2020 at 14:25
  • @KrisGoncalves Ah. I'd forgotten about that. That's unfortunate.
    – sfdcfox
    Dec 25, 2020 at 15:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .