Tales of the Salesforce Spirit: Custom Object Mass Deleter (Part I of IV)

So, I’m doing my thing at work – Salesforce Certified Developer.  A situation presents itself where I need to delete multiple records at once.  The best part is, they all belong to custom objects and salesforce only allows mass delete on select standard objects.  You know what this means then – you got to make it yourself.  Now I see the need to create a generic mass delete controller.  After a bit of deliberation between me and my best friend “I”, I came to the conclusion that this needs to be done in 4 parts.  Part I, define the interface for a “Mass Delete Searcher”  this will define the generic params and returns needed to search for the list of records to delete.  Part II – The needed entities/classes to make this work. Part III – The Mass Delete Controller – This guy will act as the generic controller to orchestrate the mass delete on Part IV.  Part IV – The Mass Delete Page – this just allows the user to customize the criteria for the mass delete.

Part I (a) – The Mass Delete Search Interface

So to be consistent and not abuse the whole “Inheritance” concept, I decided to go with an interface first to describe the format of a Mass Delete Searcher


So as shown, you can see that what we require is the “WHERE” aspect of the SOQL query, the limit and the offset.  The WHERE aspect has to be passed since the UI must provide a configurable search.  The Limit acts as my page size, and my offset as my page.  The TSearchResultItem here is really just a class that stores the Id, Description, a pointer to the SObject it refers to, and a Map of <String,String> called ExtendedProperties for the purpose of indexing extra information of the SObject into a Map.  Very useful in a Visual Force page where Reflection isn’t available for abstraction purpose.

Part I (b)  – The Mass Delete Search Example ( Class )

This is where I implement the interface itself.  This allows me the create a number of classes that implement the interface, and in the future, create a hashtable/map for the purpose of registering classes that implement an arbitrary interface of the type IMassDeleteSearcher.


To be continued….Tales of the Salesforce Spirit: Custom Object Mass Deleter (Part II of IV)

titancronusTales of the Salesforce Spirit: Custom Object Mass Deleter (Part I of IV)

One Comment on ““Tales of the Salesforce Spirit: Custom Object Mass Deleter (Part I of IV)”

  1. Jeff

    Was this a scenario where you needed to delete records, or you need to build a tool for users to delete records. If it was the former, would it not have been easier to use the Developer Console?

    Whether or not this was overkill, I enjoy your blog and thought-process. Keep it up!

Leave a Reply

Your email address will not be published. Required fields are marked *