Monday, May 27, 2013

The Mass Case Close Button

From time to time, people on the Salesforce.com forums ask how they can make a Mass Case Close button that skips the Case Close screen and just closes the cases directly.  This is just a twist on the Quick Case Close button that I have written about previously on this blog. The code is quite simple:

{!REQUIRESCRIPT("/soap/ajax/13.0/connection.js")}
var records = {!GETRECORDIDS($ObjectType.Case)};
if (records[0] == null) {
    alert("Please select at least one case to close.")
} else {
    //Get more info on the cases that were selected and generate a query out of it
    var updateRecords = [];
    //Iterate through the returned results
    for (var recordIndex=0;recordIndex<records.length;recordIndex++) {
        var caseUpdate = new sforce.SObject("Case");
        caseUpdate.Id = records[recordIndex];
        caseUpdate.Status = 'Closed';
        updateRecords.push(caseUpdate);
    }
    var result = sforce.connection.update(updateRecords);
   
    //handle errors here
    if (result.error) {
        alert('There was an error processing one or more cases');
    }
   
    //Reload the list view to show what he now owns
    parent.window.location.reload();
}


To add this code, go to Setup->Cases->Buttons and Links and make a new custom button called Mass Close.  Its Display Type should be set to List Button, its Behavior to Execute JavaScript, and its Content Source to OnClick JavaScript.  Paste the above code into the OnClick JavaScript field -- but be sure to replace the caseUpdate.Status = 'Closed'; line with a status that is present in your org. 

Now you'll have to add this button to the Case list view.  To do this, go to Setup->Cases->Search Layouts.  Click Edit next to the Cases List View entry, and add your new button from the Available Buttons section to the Selected Buttons section. As with the Contention-Proof Accept Button, the trick here is that GETRECORDIDS call -- it gets us the list of Case IDs that you selected from the list.  The rest here is simple, just put all those Case IDs into an array and set the case status fields to Closed, and call update.  Easy! Just imagine what other sorts of mass actions you could do with this method.  It's hard to fathom the creativity of the readers of this blog.

Thursday, May 23, 2013

The Quick Case Close Button

People often ask me how they can get around the Close Case page.  One option to do this is to replace the standard Close Case button with a custom button of your own.  It's remarkably easy to do! Here's how.

First, go to Setup->Cases->Buttons and Links and make a new custom button called Close Case.  Its Display Type should be set to Detail Page Button, its Behavior to Execute JavaScript, and its Content Source to OnClick JavaScript.

Now you need only paste the following JavaScript in there:

{!REQUIRESCRIPT("/soap/ajax/13.0/connection.js")}
var caseObj = new sforce.SObject("Case");
caseObj.Id = '{!Case.Id}';
caseObj.Status = 'Closed';
var result = sforce.connection.update([caseObj]);
if (result[0].success=='false') {
    alert(result[0].errors.message);
} else {
    location.reload(true);
}


This is assuming, of course, that you actually have a status called "Closed" -- but if you don't, don't despair -- just change the caseObj.Status = 'Closed'; line to a closed status that actually exists in your case status list.

Now edit your Case page layout.  Click on the Detail Page Buttons box and it will be highlighted, then click the Edit Properties button.  Here you'll be able to hide the standard Close Case button and show your new custom Close Case button. Finally test your new button by making a test case and closing it.  Voila!  The button sets the case to a closed status and reloads the page to give you feedback that in fact it was closed!  


Please note that because this trick uses the API, it will only work for Enterprise Edition and up, or for Professional Edition with the API add-on.

Monday, May 20, 2013

The Quick Email Button Revisited: Sending One-And-Done Emails with Workflow

In my popular post The Quick Email Button I reference a means of making a button that just sends the email immediately with no edit window.  I then mention that it's been deprecated for orgs that have been created since 2010.  

Salesforce.com deprecated this URL parameter for a good reason: the save=1 parameter is not particularly secure, and a clever attacker could make spoofed links to Salesforce.com to save random data to your org.  I will say this about URL hacks in general: they are hacks, and that makes them inherently unreliable.  Sometimes they will stop working.  So despite my tacit encouragement in my original post, try not to use them if you can avoid them.

The question remains, then:

How can you make a button that sends a one-and-done email?

This simple but roundabout method uses Workflow email alerts and a Javascript custom button.  Note that this method uses the Salesforce.com API, so it will only work with orgs that have the API (generally Enterprise Edition and above, or Professional Edition with the API add-on).  Here's how to do it:

1. Make a custom checkbox field on your object called "Send Email."  Don't show it on any page layouts -- it should only be used as a proxy for the workflow we'll define below.
2. Make a new workflow rule on this object and set it to run when a record is "created, and any time it’s edited to subsequently meet criteria."  Change the Rule Criteria to run if the "formula evaluates to true," and in the formula box, enter ISCHANGED(Send_Email__c).
3. Press Next and add an Email Alert that selects the proper template and sends to the person you want to send to (generally the email address of the Lead or Contact you're putting the button on).  Save the email alert.  Don't forget to activate your workflow rule!
4. Now go to your object and create a custom button on it.  Set this custom button to Execute Javascript, and put code in that looks like this (the below example is for the Lead object, you'll need to modify it slightly for any other object type):

{!REQUIRESCRIPT("/soap/ajax/16.0/connection.js")}
var leadObj= new sforce.SObject("Lead");
leadObj.Id='{!Lead.Id}';
//Update that checkbox to true, which will trigger the workflow
leadObj.Send_Email__c = true;

var result=sforce.connection.update([leadObj]); /*updating the object*/

if (result[0].success=='false') {
    alert(result[0].errors.message);
} else {
    location.reload(true);
}


5. Add this custom button to your page layouts.

And voila!  You now have a custom button that immediately sends out an email without any further user intervention.

There's another way to do this with just a custom button alone and no workflow, but it's a bit more involved on the code side.  I'll cover that in a future post on this topic.

Happy emailing!


Friday, May 17, 2013

Next Best Activity, Cross-sell and Upsell in Salesforce.com

I would be remiss if I didn't at least occasionally mention some of the stuff I'm doing now at KXEN, particularly since much of it is very much complementary to Salesforce.com's current offering.

First: for those who want to hear the werewolf's dulcet tones live, I'll be doing a webinar on this topic on May 29, 2013 -- register here.

Before I came to KXEN, I was in the call center world for over five years, and one of the most common things I heard is that the people who run those call centers want to be able to make effective offers to prospects (in telesales call centers), and upsell and cross-sell their existing customers (primarily in customer service call centers).

Until recently, the only real option for delivering these types of offers in Salesforce.com in the call center was to build a custom offer system.  Many Salesforce.com users do just that, using Visualforce, Apex and a rudimentary set of rules, and it can be quite painful.

We have recently released Predictive Offers to solve this problem.  Predictive Offers is a self-learning offer system, meaning that rather than making you code up a bunch of rules to decide what to offer to whom, it learns from your prospects' and customers' history and applies what it has learned to make a decision as to the best offer to make.  On top of that, Predictive Offers still allows you to apply certain rules to "clarify" its decisions.  For instance, some companies may want to apply an "already has" rule -- a printer company might offer you a toner cartridge even if they've sold you one in the past, but your cable company shouldn't offer you HBO if you already have HBO!  Predictive Offers supports that type of logic.  It's Force.com-native, so it works right inside Salesforce.com, and it's specifically made to be as easy to administer as Salesforce.com itself.  It works with both the Sales Cloud (in the standard Salesforce.com interface) and the Service Cloud (in the Service Cloud Console).



Check it out at the embedded YouTube video here, or even better, give it a spin with a free trial from our Predictive Offers AppExchange page.

Thursday, May 16, 2013

How To Stop People From Making Comments On Closed Cases

Sometimes people ask me how they can make closed cases "uncommentable" -- once those cases are closed, they don't want their reps to be able to make new comments on them. Traditionally the way to accomplish this would be to change the record type of closed cases and use a layout for that record type which hides the Case Comments related list.

This is not ideal, though, because it means that you can't read the comments either.  Fortunately, with Workflow From Case Comments, there is a better way.  As I mentioned in my previous blog entry, Workflow From Case Comments is a "chaining" workflow, which means that when it edits the parent case, it kicks off the workflow anew on that case object.  We can use this to our advantage in solving this problem.  Here's how.

  1. Define a checkbox-type custom field on Case called "No more comments." Do not add it to any of the Case page layouts.
  2. Make a validation rule which shows the error "You cannot add comments to a closed case" at the top of the page.  In the formula section put simply "No_more_comments__c=true". 
  3. Make a Workflow on the Case Comments object which fires when Case: Closed equals True.
  4. Make a Field Update in that workflow which sets the No More Comments field to true. 
  5. Activate the workflow rule!
Now, when you try to submit a comment on a closed case, the workflow will fire on the case comment.  This will make the modification to the No More Comments field on the Case to set it to true, which will violate the validation rule and disallow the save, showing the error "You cannot add comments to a closed case."

Workflow From Case Comments to the rescue!

Wednesday, May 15, 2013

The Quick Email Button

...or, mastering the black art of URL hacking the email page.
 
Sending an email from Salesforce.com can be a clicky operation.  You dig around for the Send An Email button, click it, click Select Template, find your template and click it, maybe type some more stuff in the email, and finally click Send.  That's a lot of clicks, especially for organizations where they just use the same template over and over.  Well, the good news is that you can make this a much less clicky operation by making a custom button which changes the URL parameters.  Technically URL-hacking is not supported by Salesforce.com, and it's technically not a supported API, so be forewarned -- but when you're on a quest to reduce clicks, you gotta do what you gotta do.
 
So let's say you have a template that you usually use for Cases which contains some pleasantries and then a merge field that adds in the text of any related Solutions.  If you've not used Email Templates much before, by the way, have a look at the sample template entitled "SUPPORT: Case Response with Solution (SAMPLE)" --  it does just what I've described here.  Anyway, what you'll want to do is make a custom button that preselects this template.  It's quite simple really.
 
  • The first thing you'll need to do is get the ID of the template you want to use.  This can be found by finding the template via Setup->Communication Templates->Email Templates.  Click on it and look in the URL -- you'll see an ID up there that looks like 00X30000000rNM0 (which may be followed by a ? with some other parameters -- ignore that stuff, just take the 15-character ID that starts with 00X).  Copy that ID into Notepad or someplace where you can get to it later.
  • Now go to Case and create a Custom Button -- let's call it Email Solution.  Set its Behavior to Execute Javascript and its Display Type to Detail Page Button.  In the Javascript area add this line of code, replacing the <your template here> with the ID of the template you saved earlier:   location.replace('/email/author/emailauthor.jsp?retURL=/{!Case.Id}&p3_lkid={!Case.Id}&rtype=003&p2_lkid={!Case.ContactId}&template_id=<your template here>');
  • Now add this custom button to your Case page layout, and voila, you have a one-click button that will bring up your email complete with template.


But wait, there's more!

To this we can actually add a few more bells and whistles.
By default the Send An Email page likes to BCC the sender.  Many call center agents I talk to find this rather annoying.  With the addition of another URL parameter to our custom button, we can stop it from BCCing anyone.  The parameter is p5, so our new code would be:

location.replace('/email/
author/emailauthor.jsp?retURL=/{!Case.Id}&p3_lkid={!Case.Id}&rtype=003&p2_lkid={!Case.ContactId}&template_id=<your template here>&p5=');
Notice at the end there the "&p5=" -- that sets the BCC area to empty.

But what if you just want to send the email in one click with no edits?

Well, you can do that too, with -- you guessed it -- one more URL parameter: the save parameter.  If I take the above code and add a save=1 to it, then when I click the button, the email will just be sent, and the Case page will refresh itself to indicate that an email was sent:

location.replace('/email/
author/emailauthor.jsp?retURL=/{!Case.Id}&p3_lkid={!Case.Id}&rtype=003&p2_lkid={!Case.ContactId}&template_id=<yourtemplate here>&p5=&save=1');

Note that this parameter only works for long-established Salesforce.com orgs -- for new orgs the save=1 parameter is disabled for security reasons.  If you have a newer org (created in 2010 or later) then you should use the AJAX Toolkit to send the email.  That will be the subject of a future blog post here.

What if you want to add some email addresses to Additional To?

Easy enough, that's p24.

And what if you want to change the From address?

You may have noticed that if you have Email To Case enabled with some routing addresses, or if you've modified the email address in the My Email Settings page in the Personal Information area of Setup, that when you go to send an email you have a choice of From addresses.  You can default this From address too!

The From address is just another parameter in the URL -- it's p26.  So taking our earlier example, let's add a From address default:

location.replace('/email/
author/emailauthor.jsp?retURL=/{!Case.Id}&p3_lkid={!Case.Id}&rtype=003&p2_lkid={!Case.ContactId}&template_id=<yourtemplate here>&p26=me@mydomain.com');

Note that the p26 default will only work for items that are actually in that From address list.
And that ends today's lesson on email buttons.  

Happy emailing!