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

Conclusion

Welcome back boys and girls. Get your crayons out and have as seat as we finally conclude this series.  Long, but worth it.

In order to get to a working result, I’m just going to pretend that we created a custom object called “Book” (Book__c) for the display purpose.  Given that this is the case, we can then assume that the implmentation of the Mass Delete Searcher from Part I – The T<MyCustomObject>MassDeleteSearcher would be as follows:

Now that we’ve gotten that out the way lets set our expectations on the table. My expectation is that the result of our code looks like that of salesforce’s mass delete page:

Mass Delete Searcher Screen shot

Salesforce.com example of a Mass Delete Searcher for Products

Now let’s begin.

The Point

The first thing we want to do is create a custom apex page for the Book. So type in your address bar (replace c.cs00.visual.force.com with  your organization url):

https://c.cs00.visual.force.com/apex/MassDeleteBookPage

In our page, we will want to set the controller to our MassDeleteCustomEntityController which we made in Part III:

<apex:page tabStyle="Book__c" controller="MassDeleteCustomEntityController">

Next, I set up my section header to reference the EntityName of my DataContext for Display purposes and add the room for the page messages:

The next section doesn’t really reference the controller except for a single search command button.  It’s just for the template that mimics that of salesforce.  Take note of the three sections which I ommitted – The INPUT, OUTPUT, and CONFIRMATION:

The input goes a little like this – From the display we looked at in salesforce, we can conclude that it’s a 3 column display with the input elements repeated in each.  Those elements are the FieldOptions, ComparisonOptions and TargetValues respectively:

Now for the output, we need a generic way to render a table of results with paging considered.  Take note, that because of the generic nature of our controller, that there is no complex display logic involved. Only simple bindings – very much like Silverlight 😉 :

It is at this point that we confirm with the user if they are sure they want to do this.  First of all, I could’ve gone with the basic javascript confirm dialog….tempting, but no.  Why? Because I said so and this is my story:

If you noticed , I had no need to custom javascript here.  All I did was take advantage of that little ViewModelState property of ours and just toggled the rendering of the actual delete versus the confirmation panel.  Popups annoy me, that’s the only reason I did it this way.Mass Delete Lead In Page

There is one small detail we have to take care of.  If you remember, in the controller, we grab a few parameters from the page during initialization.  Now, unless your user plans on typing them in, we of course need a parent page to lead us into this one.  That page is a lot simpler and looks like the image on the right.

 

To get that, all we need is a generic lead in page first.  So type in your url (of course, with your organization url):

https://c.cs00.visual.force.com/apex/MassDeleteCustomRecordsPage

From here, the main code for one of those links should look like this:

Now you get to see how it all connects.  I pass the Entity Type (et) as Book__c and the Mass Delete Type (mdt) as TBookMassDeleteSearcher.  Don’t forget your section header and page messages in this page.

And there you have it folks! You should be able to lead in from this final page into the custom page you made, execute a search and a mass delete in bulks of 200.  That’s the best I could do to help you.   I’m sure they’re many ways to do what I showed here, but in the end, I’m pretty certain that even if the end results are the same, the techniques vary.  Feel free to use them.  Stay thirsty my friends.

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

Leave a Reply

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