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
abhinav gangradeabhinav gangrade 

How to delete or truncate apex share object

I have account_share object and would like to delete or truncate records from it, pls suggest how to do it.
I think this should work. Go to developer console and run this as Anonymus Code:
list<account_share> accShare = [Select id from account_share];
Set<Id> setAccShare = new set<Id>();

for(account_share accShareobj : accShare)

//Delete all data from account_share object
delete setAccShare;

Gaurav KheterpalGaurav Kheterpal
There's a delete() ( method for this object. Be mindful though that share records for an object cannot be deleted with out deleting the object record itself.

If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others and improve the overall quality of Discussion Forums.

Gaurav Kheterpal
Certified Developer| Salesforce Mobile Evangelist| Developer Forums Moderator| Dreamforce Speaker

I think he has created a custom object called account_share not AccountShare(standard object).
Correct me if I am wrong?