1

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!

1 Answer 1

2

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());
     }
   }
 }
2
  • this is great, thank you. Are there any important considerations to be aware of when using Database.Delete() instead of the usual DML statement syntax?
    – JustinF
    Commented Aug 3, 2021 at 13:13
  • 1
    You can read about it in apex docs ;) but not much to consider except make sure that you handle error and also there is allOrNone param that makes sure that you can delete partially Commented Aug 3, 2021 at 14:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .