Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add emptyOrgRecycleBin to clean up space used by large amounts of records in the recycle bin #492

Closed
wants to merge 2 commits into from

Conversation

mkreth
Copy link

@mkreth mkreth commented Jun 2, 2022

Adds a new plugin EmptyOrgRecycleBin that will navigate to the Recycle Bin Lightning Page (/lightning/o/DeleteEvent/home) and press the "Empty Org Recycle Bin" button.

As this does not represent a "setting" in Salesforce, the plugin will simply always return { enabled: false } from its retrieve() method. To empty the org recycle bin, apply the following setting (with enabled set to true):

  "settings": {
    ...
    "emptyOrgRecycleBin": {
      "enabled": true
    }
    ...
  }

This will execute the plugins apply method and empty the recycle bin.

Closes #486

@mkreth
Copy link
Author

mkreth commented Jun 2, 2022

@amtrack I'm aware that tests are missing. I wanted to get this out to you, so you could have a look whether this is going in the right direction.

The button in the Recycle Bin lightning page does not have a unique identifier. To work around this, this plugin queries the label of the button action via the UI API and clicks the button with that label. In the next, modal confirmation dialog, the plugin simply clicks on the last button in the bottom bar of the modal. As long as Salesforce keeps their sequence of buttons (Cancel - Ok, Cancel - Empty, etc) this will work.

Copy link
Owner

@amtrack amtrack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left some comments. Please let me know what you think about them.

}

public async apply(config: Config): Promise<void> {
const deleteEventEmptyAllButtonSelector = `a.forceActionLink[title="${await this.determineDeleteEventEmptyAllActionLabel()}"]`;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that we assume the "Empty" button in the dialog is the last button,
can we maybe also just assume the "Empty Org Recycle Bin" is the last item of the forceActionsContainer?
As far as I can see, the button is there regardless if there are items in the Recycle Bin or not and I'm able to click it even if the Recycle Bin is empty.

Suggested change
const deleteEventEmptyAllButtonSelector = `a.forceActionLink[title="${await this.determineDeleteEventEmptyAllActionLabel()}"]`;
const deleteEventEmptyAllButtonSelector = `ul.forceActionsContainer li:last-of-type a`;

In that case we could go without using the UI API for simplicity and performance.
But it's great to see a use case of this API. 👏

@@ -0,0 +1,13 @@
{
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about naming the directory simply recycle-bin?

In this case, the schema could look like this:

{
  "$schema": "http://json-schema.org/draft-07/schema",
  "$id": "https://github.com/amtrack/sfdx-browserforce-plugin/src/plugins/recycle-bin/schema.json",
  "title": "RecycleBin Settings",
  "type": "object",
  "properties": {
    "emptyOrgRecycleBin": {
      "title": "Empty Org Recycle Bin",
      "description": "All items are permanently deleted. You can't undo this action.",
      "type": "boolean"
    }
  }
}

and a config could look like this:

{
  "$schema": "../schema.json",
  "settings": {
    "recycleBin": {
      "emptyOrgRecycleBin": true
    }
  }
}

@@ -0,0 +1,8 @@
{
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you start developing the tests,

  • enable.json could be renamed to empty-org-recycle-bin.json
  • disable.json could probably be removed

await page.waitForSelector(deleteEventEmptyAllButtonSelector);
await page.click(deleteEventEmptyAllButtonSelector);
await page.waitForSelector(SELECTORS.EMPTY_BUTTON);
await page.click(SELECTORS.EMPTY_BUTTON);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my tests, the recycle bin was not emptied.

Maybe we need to wait for a successful response from the server like this:

Suggested change
await page.click(SELECTORS.EMPTY_BUTTON);
await Promise.all([
page.waitForResponse(
response =>
response
.url()
.includes(
'RecycleBinActions.emptyOrgRecycleBin=1'
) && response.status() === 200
),
page.click(SELECTORS.EMPTY_BUTTON)
]);

@amtrack amtrack marked this pull request as draft June 2, 2022 19:38
@amtrack amtrack closed this May 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Automate "Empty Org Recycle Bin"
2 participants