function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
gjsgjs 

Truncate Custom Object: "instantaneous" removal of all rows from a custom object with limited options to recover the data.

We have a beta version of a functional equivalent of TRUNCATE SQL available on Sandbox organizations. Please open a case with support if you would like to try it out.  We will make a decision on when to GA based on adoption and feedback.

 

 

Truncating a custom object does the following:

  • Permanently disassociates ALL the object's data records from the object. You will not be able to operate on them using this object and they will not be recoverable from the Recycle Bin.
  • Recalculates values in Roll Up Summary Fields in parent objects that reference the object. You will not be able to recover the values that existed prior to the truncate. 
  • Creates a "shadow" custom object . This is a deleted custom object  associated with the truncated data records. Its name consists of the truncated object's name suffixed by "_trunc_n" where n is the number of times the object has been truncated. Like any deleted object, the shadow object will appear in the deleted objects list until you permanently erase the object and its data, or 45 days have passed. While it is in the deleted objects list  you can undelete the "shadow" and the data stored in it to create a new custom object. An undeleted  "shadow" custom object will not be a clone of the truncated table. It will not have any of the truncated object's :
      • relationships with other objects. Any foreign key fields will be converted to read-only text fields.
      • Autonumbers. AutoNumber fields  will be converted to read-only text fields
      • workflow rules or actions 
      • reports
      • formula fields
      • roll-up summary fields
      • validation rules or approval processes
      • Apex Code triggers
      • translations
      • field history
Cory CowgillCory Cowgill

Greg,

 

Very interesting. I've got a few simple questions:

 

If you perform a TRUNCATE on the Object, will it fire the Delete Trigger on the Object?- Seems like no?

 

When you recover the custom object will it fire any UnDelete Triggers? - Seems like no?

 

Whats the advantage of performaing TRUNCATE versus doing a Mass Delete via DataLoader or Apex API Delete (Select Id from X__c); delete x;? API Call / SOQL / Goveronor Limits?

 

Just looking for some clarity on what might be good use case to use this versus other methods we've been using for a while.

 

Thanks!

gjsgjs

Hi Rory,

 

No, it will not fire any triggers.

 

The advantage over mass delete, API or Apex is speed. This is the only way to delete all data without touching every row in the object. The speed to truncate will be the same whether the object has millions of rows or one. 

 

Regards,

 

Greg

IvanB@LMIvanB@LM
Hi, We desperately need 'truncate-like operation'. We have an ongoing project we will refresh/reload large data about 8mil recs daily into a custom SF object. Deletes are not fast for our load window. Has topic discussed in this post (truncate custom object) considered for prod orgs ? If not, what are alternatives currently available ? Thanks, Ivan Belal
Veeru AVeeru A
As the release notes say, this is not available to the API or to SOQL...correct? SO this is always just a manual click process. I too need to quickly tuncate an object in code or a button on a VF page. We create dynamic tables on a weekly basis and then relead the next week with all new data and there are currently 6000 plus records there. I am getting uncomfortably close the 10000 governor limit. This is something that woule be a no brainer in a normal SQL programming environment. 

Please make this available to APEX or offer an alternative Lazy Delete or the like. 

Thanks.
Veeru AVeeru A
p.s. Just a note to others...if you truncate the data it will still sit there and count against your data percentage until the sweeper program cleans up..could be quite awhile too. So beware...truncate in SF is not like truncate in a native DB.