Jul 302009
 

A question came across Twitter today – how can I mass delete from a related object.  A great, free little application on the Salesforce.com Appexchange – Mass Delete – helps out with this, but it only comes with standard objects.  Also, with the increase of wonderful, popular appexchange apps, some are running into limits for the number installed.  So what is one to do?  Well, here is some javascript, and how to set up a button for your related lists so that you can mass delete in just a couple of clicks.

How Do I do this?

  1. First, go to the object you wish to create a list button for.  If you wish to do this on accounts (or any standard object), click Setup, Customize, Accounts (or the standard object you wish to use), Buttons and Links. For a custom object, click Setup, Create, Objects and then click on the object you wish to.
  2. Under the Custom Buttons and Links related list, click the New button.
  3. Enter the following information for the button:
    Label: Mass Delete
    Name: Mass_Delete_Object (ie: Mass_Delete_Account)
    Display Type: List Button, and check off “Display Checkboxes”
    Behaviour: Execute Javascript
    Content Source: OnClick Javascript

    Mass Delete button setup

    Mass Delete button setup

  4. In the detail box, enter the following:
    {!REQUIRESCRIPT(“/soap/ajax/15.0/connection.js”)}

    var records = {!GETRECORDIDS( $ObjectType.ObjectAPIName )}

    if (records[0] == null) {
    alert(“Please select at least one record.”) } else {

    var errors = [];
    var result = sforce.connection.deleteIds(records);
    if (result && result.length){ var numFailed = 0; var numSucceeded = 0;
    for (var i = 0; i < result.length; i++){
    var res = result[i];
    if (res && res.success == ‘true’){
    numSucceeded++;
    } else {
    var es = res.getArray(“errors”);
    if (es.length > 0) {
    errors.push(es[0].message);
    }
    numFailed++;
    }
    }
    if (numFailed > 0){ alert(“Failed: ” + numFailed + “nSucceeded: ” + numSucceeded + ” n Due to: ” + errors.join(“n”));
    }
    else {
    alert(“Number of records deleted: ” + numSucceeded);
    }
    }
    window.location.reload();
    }
    Now, the only part you need to change is the second line, where it says $ObjectType.ObjectAPIName.
    If you were doing this on accounts, you would use $ObjectType.Account.  For a custom object, find the API Name on the top of the main object page (For a custom object called Projects, with an API Name of Projects__c, you would enter $ObjectType.Projects__c.

  5. Click the Save button.  You will know have this button available on all lists.
  6. The final step is to add this to all your lists.  To do so, you must edit the page layout for the object you would be on to see the list.  As an example, if you wanted to delete projects from an account page, you would edit the Account page layout, go to the related list, edit the Project related list, and add the Mass Delete button.   Save the layout change, and you are done.
MassDelete2

Using the Mass Delete Button

Mass Delete Success Alert

Mass Delete Success Alert

When using the button, check off the checkbox beside the record(s) you wish to delete, and click the Mass Delete button.  Upon it finishing, a pop up will alert you to the number of records which has been deleted, and then refresh your page.

Hope you find this useful – and one final caviat.  Please delete with care…although the records will be in your recycle bin, make sure you know what you are deleting before doing so!

Enjoy the week!

Nik

 Posted by at 1:14 pm
Jul 162009
 

Wow – two months since my last blog. Apologies folks – for those of you who came back to see if anything was new. Lots is….

Where have I been? Well, it is the summer time, and as a dad, there have been MANY weekends where I have been travelling with my daughter to her Highland Dance competitions (she loves to dance! and is not too bad at it either), which seems to take up a boat load of time. And then there was work, which while starting to slow to a much more manageable level was capital-C crazy for a while. During that crazy time, no blogs – but also, for a wee bit, no tweets either….and while I was gone, man did things change!

It seems that celebrities, media, and even many people I know grabbed onto the twitter bandwagon, and registered. Reading through many tweets when coming back, I found some who loved being able to follow their favourite band (being able to say something back and maybe – just maybe having them read it, let alone reply was an amazing thought!). Companies joined in the fray, using twitter to spread the word on their product or service (albeit sometimes in a spam-like manner). Many used it as a micro-blog on their day (this is not new, more of an increase – including tweeting on the contents of their morning breakfast, business meeting or tea-leaf reading). And others reminisced on a day when twitter was much simpler, and was not filled with celebrities, companies, and other.

This has changed Twitter’s topography – especially if you look at who follows people, and the tweet levels of searches. Looking at twitterholic.com (a neat little site to keep track of who you are following or being followed by. Here you can see the top Tweeters based on followers (which is important to some). The top 5? Ashton Kutcher, Ellen DeGeneres, Britney Spears, CNN Breaking News and Oprah.

And of course, with change comes sentiment and opinion. Some have left twitter for friendfeed (very popular to early Twitter adopters such as Robert Scoble). Others now send messages to friends or celebrities on hopes of starting a flame war or gaining attention (there are a few examples which popped into my head, but i don’t feel like giving them airtime). Others lurk much more, while many continue to do what they did.

Me? I still tweet, and when I have time I follow what people are saying on Twitter. Those who know me know my love of music, and during Cisco Ottawa Bluesfest, I’ve passed along pics or thoughts, and even heade over to a stage or two after reading other commenting on a hidden gem. I still have my Salesforce search, and will answer questions when people have a query I think I may be able to help. And yes – I am sure you’ve seen a comment or eight about bagpipe sounds, soccer, TV or anything else on my mind. Do I get responses all the time? No – but that’s ok. To paraphrase the Arrogant Worms (a great Canadian band!) Twitter is really, really big. And as a user of this really, really big application, if I don’t like what I see, I can just move on.  I’m just happy to be part of the pod.

 Posted by at 8:29 am  Tagged with: