5

PROBLEM STATEMENT

I have a 'Compose Email' component which is embedded in the docked utility bar. Please see below image for clarity. I am using lightning:fileUpload to allow multiple email attachments, which get automatically attached to the specified parent record. If the user attaches stuff and ultimately sends out the email, then we are golden. But what if the user does NOT send out the email? In that case I need to delete all the 'temporary' attachments from the parent record that were intended to be sent but never were.

enter image description here

WHAT I HAVE TRIED SO FAR

onUtilityClick() in lightning:utilityBarAPI

From my component init, I call the below method which finds the first utility item and implements a handler for onUtilityClick. It fires fine when I click on the actual utility bar item, BUT it does NOT fire when I minimize the utility by clicking on its header or the minimize button. I went through the utilityBarAPI methods here but none seem to be relevant for my goal.

handleUtilityBar : function(component, event, helper) {
        var utilityAPI = component.find("utilitybar");

        utilityAPI.getAllUtilityInfo().then(function(response) {
            var utilityId = response[0].id;
            var onComposeEmailMinimize = function(response){
                console.log('--------------------> WORKS ON UTILITY ITEM CLICK, BUT NEEDS TO FIRE ON UTILITY MINIMIZE AS WELL');
            };

            utilityAPI.onUtilityClick({
                utilityId: utilityId,
                eventHandler: onComposeEmailMinimize 
            }).then(function(result){
                console.log('--------------------> result = ' + result);
            }).catch(function(error){
                console.log('--------------------> error = ' + error);
            });

        })
        .catch(function(error) {
            console.log('-------> utilityAPI ERROR: ' + error);
        });

    },

unrender in RENDERER

I have also tried my luck handling unrender in RENDERER, but no dice.

unrender: function () {
    this.superUnrender();
    console.log('--------------------> UNRENDER CALLED');
}

Handle component destroy

As a measure of last resort, I also tried (a long shot) to see if destroy event is called upon minimize, but nope.

<aura:handler name="destroy" value="{!this}" action="{!c.handleDestroy}"/> 

QUESTION

How can we delete the 'orphan' ContentDocuments when:

  1. User minimizes 'Compose Email' utility, or
  2. Ends up refreshing the page, or
  3. Navigates away from the page they are on?
  • This problem is very common. one solution would be to run a scheduled batch, lets say every day, and delete all orphan files (files that emails have not been sent). You can add to this solution a file delete function and to execute it when User minimizes 'Compose Email' utility or other events that you can handle – Itai Shmida Jul 29 '18 at 12:04
  • How would you detect minimize action to a utility? There is way to minimize an open utility, but nothing that tells that a user has clicked on the minimize button. – Lightning Evangelist Jul 29 '18 at 12:15
  • I do not know if you can do that – Itai Shmida Jul 29 '18 at 13:51
  • Upvoted ... one would think this would be an action developers would be able to capture !!! But so far I cannot find a way to listen for it. – jordan.baucke Nov 26 '18 at 22:23

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.