I just ran a few consecutive tests of inserting and deleting a bunch of groups via the developer console (execute anonymous).

Inserted 50 Group records:

List <Group> groups = new List <Group> ();

for (Integer i = 0; i < 50; i++)
    Group g = new Group();
    g.Name = 'ggg' + i + 'test';

insert groups;

Runs fine, and pretty quick.

Then I tried to delete the same subset of groups. My org has around 10,000 existing groups and I'm aware that the following query will take a bit longer because it touches all rows:

delete [SELECT Id FROM Group WHERE Name LIKE 'ggg%' LIMIT 50];

This thing runs for 25 to 30 seconds! I expanded the stack tree - the query only takes a few milliseconds and the rest of the time is the actual deletion of the groups.

I'd love to know what exactly is happening when a group is being deleted. Is there a valid reason for this execution to last around 30 seconds?

  • Not sure whether this helps a little bit or not. My org has only 37 existing groups and 87 after inserting the 50 ones. But it still takes about 15 seconds to accomplish the deletion. – Lance Shi Feb 21 '17 at 4:58
  • That is still a long time to delete 'empty' records... Wondering what sort of processing is going on in the background... – Boris Bachovski Feb 21 '17 at 5:06
  • I thought it might have something to do with sharing recalculations (although 30 secs would still be absurd especially for groups with no members), but even after enabling and turning on the Defer Sharing Calculations option in my dev org, groups are still taking an inordinate amount of time to delete. Interesting... – Bow-chicawow-ers Feb 22 '17 at 17:29
  • @BorisBachovski Anything useful in the debug log if you ratchet the Database logging level down to Finest? – Daniel Ballinger Feb 22 '17 at 22:09
  • 1
    @DanielBallinger The greatest portion of the time is spent between DML_BEGIN and DML_END, though not much info can be found in between. What's interesting is this line (from the cumulative profiling) External entry point: public static void execute(): executed 1 time in 25153 ms which suggests that some kind of system batch is fired up. That made me check for background apex job logs, though I can't see any that refer to what was executed. – Boris Bachovski Feb 22 '17 at 23:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.