back to resources
Delete the record on Approval
April 28 2022 • 25 min read

front picture

BUSINESS REQUIREMENT

In order to protect the data from accidental deletion, any record deletion (opportunity, lead, account etc..) requires an approval from manager or all stakeholders before deletion.

With this blog, you will learn how to achieve the above requirement by creating a screen flow to trigger an approval process and a record trigger flow to delete an Opportunity record after approval.

STEPS FOR DELETE APPROVAL 

  1. Create a Custom Field
  2. Create Approval Process
  3. Create Screen Flow
  4. Create Custom Quick Action Button
  5. Create a Record Triggered Flow

CREATE A CUSTOM FIELD

  1. From the home page click on Gear Icon at the top, go to Setup.

    setup image

  2. Select Object Manager → In the Quick Find, Search & Select Opportunity.

    dra image 2

  3. Select Fields and Relationship → Click New → Choose Pick List Data Type → Click Next.

    dra image 3

    Picklist help to hold multiple values.

  4. Label the Field as “Delete Approval Status” and Enter the below mentioned values each in a new line.

    • Submitted

    • Approved

    • Recalled

    • Rejected

      dra image 4

  5. Click Next.

  6. Select the Profiles to which you want to grant visibility access → Click Next.

    dra image 5

  7. “Delete Approval Status” field is used in order to trigger the flow and for quick action button visibility. We do not want to add this field in the Page layout. Uncheck the box as mentioned in the screenshot.

    Click Save.

    dra image 6

Create Approval Process

  1. In Order to learn how to create an Approval Process please visit Approval Process in Salesforce.

  2. We created an Approval Process where the entry criteria is Delete Approval Status equals Submitted and added one step where three users should unanimously approve in order to delete the record.

  3. The below screenshot shows how our Approval Process looks like. You can add multiple steps if required.

    dra image 7

  4. Add Field update action in Final Approval Action. This update action will trigger the record trigger flow to delete the record. Click Add New  → Select Field Update.

    dra image 8

  5. Enter Field Update Name as Field Update After Approval. Select Delete Approval Status field in Field to Update. For Specify New Field Value, under Picklist Options choose “A Specific value” and select “Approved” from the dropdown (Please refer the below image).

    dra image 9

  6. Click Save.

  7. Similarly, create field updates for Final Rejection Actions. For Picklist value select  Rejected as the Value.

    dra image 10

  8. Similarly, create field updates for Recall Actions. Choose Recalled as the picklist Value.

    dra image 11

  9. Now Activate the Approval Process.

Create Screen Flow

dra featured image

  1. If you are in the Approval Process Screen Click Home → In Quick Find Box search for Flows and select it→ Click New Flow Button at the top right corner.

    dra image 12

  2. Select Screen flow → Click Create.

    dra image 13

  3. Click New Resource.

    dra image 14

  4. Select Variable as Resource TypeText as Data Type → Enter recordId  as API Name → Check on Available for Input → Click Done.

    dra image 15

  5.  Click (+) Icon → Select Update Element.

    dra image 16

  6. Label the Update element name as “Update Delete Approval status” →Under How to find records to update and set their values Select Specify Conditions to Identify records and set fields individually option.

    dra image 17

  7. For the Object choose Opportunity → for condition requirements to update records under the Filter Opportunity Records choose All Conditions Are Met(AND) → choose Opportunity Id Equals to recordId.

    dra image 18

  8. Under set field values for the Opportunity Records, Choose the field as Delete Approval Status and for the value select Submitted.

    dra image 19

  9. Click Done.

  10. Add the Action Element into the Flow → Enter Submit in the search box → It will display the Approval Process action → Select “Submit for Approval”

    dra image 20

  11. Name the action element as “Trigger Approval”. Under Set Input variables, for the Record ID choose the recordId variable and for Approval Process Name or ID use the API name of the Approval Process i.e. Approval_Process_to_delete_Opportunity.

    dra image 21

  12. Click Done.

  13. Then Add Screen Element. Name the Screen Element as Delete End Screen. Under Configure Header uncheck the Show Header option.

    dra image 22

  14. Hide the Previous and Pause buttons. For the Next or Finish Button, choose Use a custom label and enter the label as “Close”.

    dra image 23

  15. Drag Display Text component onto the screen from the left components pane . Label it as “End Screen” and add Content inside. Here we added “Your record is submitted for approval, once everyone  approves, the record will be deleted automatically”.

    dra image 24

  16.  Click Done.

  17. Save the flow and Name it as “Submit for Approval screen flow” → Click Save and Activate the Flow.

    dra image 25

Create a Custom Quick Action (Object Specific)

  1. Go to Object Manager → Select Opportunity.

  2. Select Buttons, Links and Actions → Click New Action.

    dra image 26

  3. Select Action Type as Flow.

    dra image 27

  4. Select the Screen Flow “Submit for Approval screen flow” → Label the action Button as “Delete” and Click Save.

    dra image 28

  5. Add the created custom action button in the Opportunity Page layout. Open any opportunity record → Click Gear Icon → Click Edit Page. It will open Lightning App Builder.

    dra image 29

  6. Click the highlight Panel and on the right side click “Add Action”.

    dra image 30

  7. Select Delete quick action that we created.

    dra image 31

  8. Under Set Action Visibility Add Filter Condition as Delete Approval Status Not Equal Submitted → Click Done → Click Done again.

    dra image 32

  9. Drag the Quick Action to Top.

    dra image 33

  10. Click Save and Go back to your record page.

    dra image 34

  11. Now you should see the Delete Custom Button in the record page.

    dra image 35

Create a Record Triggered Flow

  1. Go to Setup → In the Quick find Box search and select Flows → Click New Flow → Select Record Triggered Flow → Click Create.

    dra image 36

  2. In the start element choose Opportunity as the Object and for Trigger the Flow When option choose A record is updated.

    dra image 37

  3. Under Set Entry conditions Condition Requirements → choose All conditions are met(AND) → Choose Delete Approval Status as Field,  Equals as Operator and Approved as Value.

    dra image 38

  4. When to Run the Flow for Updated Records choose Only When a record is updated to meet the condition requirements →  Optimize the flow for Option choose Actions and Related Records → Click Done.

    dra image 39

  5. Make sure Auto Layout is selected and Click (+) Icon.

  6. Add Delete Element and name it as “Delete Record” → Under Select Records to Delete select the recordId from the flow → Click Done.

    dra image 40

  7. Connect the start element and Delete ElementSave and Activate the flow.

Testing

  1. Open any Opportunity. You can see the delete button displayed at the top of the page and also you won’t see any Approval History. Click Delete Button.

    dra image 41

  2. Once the delete Button is clicked. It will display a popup → Click Close.

    dra image 42

  3. The Opportunity will be submitted for Approval.

    dra image 43

  4. Once everyone approves, the Opportunity record will be deleted Automatically.

    dra image 44

Note : If the Custom Action Button is not visible in the Page layout, Check the Run Flows permission in Profile settings.

Go to SetupProfile → Open the Particular Profile which you want to enable the  permission to → Go to System Permissions → Check the Run Flows option →Click Save.

Refresh the record Page and Now the button will be visible.

dra image 45

Wrapping it up

In this Blog we have covered how to enforce the approval process before deleting an opportunity record using two flows (screen flow and record triggered flow). The record is submitted for Approval from the screen flow and the field updated using field update actions is used as an entry condition for the record triggered flow.

Leave a Comment

Your email address will not be published

© 2022 Digital Biz Tech