Concepts or coding lessons of Salesforce that you can implement easily

5 Simple Steps to Delete Salesforce files Owned by Other Users

In Lightning Experience, we have limitation who can Delete Files - 
Only a File Owner and Users with the “Modify All Data” permission can delete all Files !!!
This is working as designed for Lightning version.

We recently moved from Salesforce Classic to Lightning Experience .

While transition to Lightning Experience, we have enabled "Save Email-to-Case attachments as Salesforce Files" Email-to-Case Settings and also enabled "Files uploaded to the Attachments related list on records are uploaded as Salesforce Files, not as attachments" from Salesforce Files Settings.

So whenever we receive attachments in Email-to-Case or Upload any attachment into Salesforce, it automatically convert into files by Salesforce.

We have business process setup where we have to delete some confidential files received via Email-to-Case. In this blog I am going to explain how I achieve this.

To meet requirement, we have only one option available which is Customization.

I have used one idea, "Whenever Case Owner changes then Set that Owner as an Owner for Files of that Case".

If you similar business process then Follow below 5 Simple Steps :

1. Create Apex class namely "ContentDocumentController" with Without Sharing and add below code:

2. Create Process builder on Case object for INSERT / UPDATE event.
3. Define Criteria for this Action Group : 
 AND(
NOT(ISNEW() ),
ISCHANGED([Case].OwnerId ),
BEGINS([Case].OwnerId, "005") 
)
4. Set below things as Immediate action:




5. Activate Process Builder.

Enjoy! If you have any questions, comments etc. please feel free to let me know. As always, please feel free to get in touch me as I would be more than happy to assist you with any of your Salesforce development needs.


Subscribe blog for More updates !!! 


Read More: WhatsApp on Salesforce Integration in 5 Steps
                    Which Salesforce API Do I Use in Integration?
                    When To Use Salesforce REST API  
                   When To Use Salesforce SOAP API 
                   When To Use Salesforce Bulk API 

Latest Salesforce Interview Questions and Answers:

Modal/Popup Box In Lightning Component – Salesforce

How to implement Model or Popup Box in Lightning Component?

Use the below code to implement it. 

ModelDemo.cmp => Lightning Component Code

<aura:component>
    <!--use boolean attribute for Store true/false value,make default to "false" so modal box are not display on the load of component. --> 
    <aura:attribute name="isModelBoxOpen" type="boolean" default="false"/>
    
    <!--Use "slds-m-around_xx-large" class to add standard X-Large padding to the component--> 
    <div class="slds-m-around_xx-large">        
        <lightning:button variant="brand"
           label="What is Lightning Modal/PopUp Box?"
           title="What is Lightning Modal/PopUp Box?"
           onclick="{! c.openModel }" />
        <!--Use aura:if tag to display Model Box, on the bese of conditions. [isModelBoxOpenboolean attribute] -->   
        <aura:if isTrue="{!v.isModelBoxOpen}">            
            <!--###### MODAL BOX Start######--> 
            <section role="dialog" tabindex="-1" aria-labelledby="modal-heading-01" aria-modal="true" aria-describedby="modal-content-id-1" class="slds-modal slds-fade-in-open">
                <div class="slds-modal__container">
                    <!-- ###### MODAL BOX HEADER Start ######-->
                    <header class="slds-modal__header">
                        <lightning:buttonIcon iconName="utility:close"
onclick="{! c.closeModel }"
alternativeText="close"
variant="bare-inverse"
class="slds-modal__close"/>
                        <h2 id="modal-heading-01" class="slds-text-heading_medium slds-hyphenate">Lightning Modal/PopUp Box</h2>
                    </header>
                    <!--###### MODAL BOX BODY Part Start######-->
                    <div class="slds-modal__content slds-p-around_medium" id="modal-content-id-1">
                        <p><b>Sit nulla est ex deserunt exercitation anim occaecat. Nostrud ullamco deserunt aute id consequat veniam incididunt duis in sint irure nisi. Mollit officia cillum Lorem ullamco minim nostrud elit officia tempor esse quis. Cillum sunt ad dolore quis aute consequat ipsum magna exercitation reprehenderit magna. Tempor cupidatat consequat elit dolor adipisicing asdasd asdetg jhkirty iouiodc eryrm, ksjlkdfjoern  oksmelsm ljsflr.
                            </b>
                        </p>
                    </div>
                    <!--###### MODAL BOX FOOTER Part Start ######-->
                    <footer class="slds-modal__footer">
                        <lightning:button variant="neutral" 
label="Cancel"
title="Cancel"
onclick="{! c.closeModel }"/>
                        <lightning:button variant="brand" 
label="Ok"
title="Ok"
onclick="{! c.submitBox }"/>
                    </footer>
                </div>
            </section>
            <div class="slds-backdrop slds-backdrop_open"></div>
            <!--###### MODAL BOX Part END Here ######-->            
        </aura:if>
    </div>
</aura:component>

ModelDemo.js => Lightning Js Controller Code

({
   openModel: function(component, event, helper) {
      // for Display Model,set the "isModelBoxOpen" attribute to "true"
      component.set("v.isModelBoxOpen", true);
   },
   closeModel: function(component, event, helper) {
      // for Hide/Close Model,set the "isModelBoxOpen" attribute to "False"  
      component.set("v.isModelBoxOpen", false);
   },
   submitBox: function(component, event, helper) {
      // set the "isModelBoxOpen" attribute to "False for close the model Box.
      component.set("v.isModelBoxOpen", false);
   },
})


ModelDemo.App => Lightning component App

<aura:application extends="force:slds">
    <c:ModelDemo/> <!-- here c: is org. namespace prefix-->
</aura:application>

Now Run ModelDemo.App and click on What is Lightning Modal/PopUp Box? button. :)

Subscribe blog for More updates !!! 


Read More: WhatsApp on Salesforce Integration in 5 Steps
                    Which Salesforce API Do I Use in Integration?
                    When To Use Salesforce REST API  
                   When To Use Salesforce SOAP API 
                   When To Use Salesforce Bulk API 

Latest Salesforce Interview Questions and Answers: