-
Notifications
You must be signed in to change notification settings - Fork 39
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
Conversation
used by large amounts of records in the recycle bin.
@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. |
There was a problem hiding this 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()}"]`; |
There was a problem hiding this comment.
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.
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 @@ | |||
{ |
There was a problem hiding this comment.
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 @@ | |||
{ |
There was a problem hiding this comment.
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 toempty-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); |
There was a problem hiding this comment.
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:
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) | |
]); |
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 itsretrieve()
method. To empty the org recycle bin, apply the following setting (withenabled
set totrue
):This will execute the plugins
apply
method and empty the recycle bin.Closes #486