Visual Workflow – How to Create an Object-Agnostic Flow to Automatically Determine and Delete a Record

deletescreen-flowvisual-workflow

I want to build a screen-flow which runs a Delete action on a record in system mode (ignores user permissions). I want to implement this same screen flow on multiple objects (~10 in total).

I would ideally like to build the screen flow in an object-agnostic way, such that it only needs 2 inputs:

  • Record ID
  • Object API

The flow would then pass these 2 parameters into 1 Delete element to delete the record. From what I can tell, it doesn't seem possible to dynamically pass variables into the Delete element, so my only 2 remaining options are:

  1. Use a decision node + separate delete elements
  2. Use an invocable Apex method (which can be built to dynamically receive those 2 inputs I listed above)

However, even in those 2 alternative solutions, I still need a way of automatically detecting what Object the flow has been launched on. How can that be done?

Any thoughts or advice on this solution would be appreciated!

Best Answer

All you need to delete the records is the recordId to query the records and delete it.

Note you don't need the Object Name at all for your use case if it is just deleting the records.

Now to make it dynamic, use your second approach of creating a simple Innvocable action via apex that takes in ID and deletes it.

A Sample pseudo-code is below,

public inherited sharing class DeleteRecords {

@InvocableMethod(label='Delete Records' description='Deletes Bunch of records')

public static void delete(List<Id> recordIds){
    
   try{
       Database.Delete(recordIds);
    } catch(exception e) {
       throw new exception(e.getMessage());
     }
   }
 }
Related Topic