Delete Records Element Delete Records Element

 


Delete Records Element

Hmm another element with a tricky name smile

This flow is almost identical to the last one, we run a Get Records to get the Account record first (1).

Next, using the Account ID from the first query, we run another Get Records to get all the Contact records (2) that are related to that account. We store these in an automatic record collection variable (Contacts from getContacts).

We then Loop through the records in this record collection variable (3) to see if any have a blank mailing address (4). If they do, we Assign them to a new record collection variable - rc_ContactsToDelete (5).

When the loop is finished, we perform the Delete Records - deleting those records in our collection variable (6).

 

When we have exercises where you are creating a flow like this, you will be provided with all of the detailed steps. For now, we just want to introduce the concepts.





Here is the simple delete step:


When the flow is run in debug mode, we can see (in one of the iterations through the loop) in (1) that we have found a contact where our mailing city is blank. It is added to our REcord Collection (rc_ContactsToDelete) and finally, in (3) the loop is finished and ready to perform the deletion.



Deleting Records in a Flow


For this flow, you will need to install some flow components from: unofficialsf.com

The main component we need is the datatable component but it requires two other components to be installed first.

Note: You must wait for each to finish installing before commencing to install the next one.


Before continuing, make sure you have all three packages installed:


Note: The versions will be higher numbers than shown here.

In June 2022, the versions are:

  • FlowActionsBasePack Version 3.0.0
  • FlowScreenComponentsBasePack Version 3.0.7
  • Datatable ver 4.0.5


One more thing to check


The Datatable element uses a Visualforce page to select and set the columns to display.

It requires these settings to be disabled:




The Finished Flow

When you have finished building this flow, it should look like this:



Create a new Screen Flow

Add a new variable that will be used to keep a count of records (for later)




Add another new variable that will be a record collection that will contain the records you want to delete (for later)



Next, add a Get Records element to get the contact records:



Scroll to the bottom of the elements list (left panel) and find and drag over a new Datatable element:

Note: If you have not installed this properly, it will not appear. You may find you need to exit flow and start again to get it to show up the first time.



Configuring the Datatable element:

  • give it an API Name
  • Select the object from where you will get the records (contact)
  • Display the records retrieved by get_Contacts (previous element)



Show row numbers and add a border to the table:



Click on Configure Columns:



Pick the fields to display in the table:



If you get a blank page here and cannot select any columns to display, go back up to "One more thing to check" and disable the clickjack protection for Visualforce.



Select these fields to display:


You can adjust the column widths here:

(by clicking the down arrow next to the heading labels you can also add icons, wrap text and change the label names too)



Click Next to save:



Add a new Assignment element that assigns the records you want to delete to the collection variable:



Add another assignment to count how many records you have ready for deletion:



Add a decision element - do we have any records to delete?

(Note: If we don't include this and no records are selected for deletion an error will occur)



Add a new Delete Records element and pass the record collection to it:



Save, activate and click debug to run your new flow:



Return to your Sales App and confirm the contact record(s) you selected have been deleted successfully.



Celebrate. You can now delete records!!


 

No comments: