Sunday, November 8, 2015

Salesforce Case/Lead Assignment Rules

One of the nice features of Salesforce Cases and Leads is the ability to setup Assignment Rules that will assign a record to a specific queue and send a notification when certain criteria are met. In this article I will show the basics of setting up Case Assignment Rules and how to they work with the REST API. Lead Assignment Rules work basically the same way so I will only cover Cases.

To setup the rules, go to Setup, App Setup, Customize, Cases and select Case Assignment Rules. You will see a list of any rules that are currently setup.

image

Click New to create a new rule and enter a unique name. At this point you can check Active to enable this rule immediately, or you can wait until you have completed the setup of the rule and activate it later.

 

image

Once you enter the name you will be taken back to the rule list where you can click on the rule to edit it.

image

Next to Rule Entries, click New to create a new rule entry. Here I have setup a rule that will assign the case to the US – Platinum Gold queue when the priority is High and the Reason is Breakdown. The sort order at the top is used if you have more then one rule and determines the order they are applied. Once the criteria of a rule is met none of the other rules will be evaluated. If you want the user or queue notified then be sure to select an e-mail template otherwise the e-mails will not be sent but the cases still will be re-assigned.

image

Once you have completed the rule entry you will be returned to the initial screen for the rule where you will want to edit the Rule Detail and select active to activate the rule.

When you use the REST API to create or update a Case all the active rules will be applied. The API also provides an HTTP header called Sforce-Auto-Assign that gives you some more control over this. If you are using the System.Net.HttpWebRequest class you would add the header like this:

request.Headers.Add(“Sforce-Auto-Assign: TRUE”);

There are three possible values for this header. Setting it to TRUE will cause all active assignment rules to be applied, which is the default behavior if you leave off the header. If you set it to FALSE, none of the rules will be applied. The final option is to use the id of an assignment rule like this:

request.Headers.Add(“Sforce-Auto-Assign: 01QE0000000bJiI”);

In this case, only that one rule will be applied, and it will be applied even if it is not active. You can get the Rule ID from the URL while you are editing the rule:

setup/own/entityruledetail.jsp?id=01QE0000000bJiI&setupid=CaseRules

Saturday, August 15, 2015

C# Null-Conditional Operator

With the recent release of Visual Studio 2015 we also get the new version of C# with some nice new language features. In this post I will talk about one of my favorites, the Null-Condition Operator.
Let’s say I have these two classes (obviously over simplified for the purposes of this article)…

class SalesOrder
{
    public Address SoldTo;
}

class Address
{
    public string PostalCode;
}


If  we then declared an instance of SalesOrder and wanted to access the PostalCode property and trim off the spaces we would do this…

string zip = order.SoldTo.PostalCode.Trim();

This line would work ok only if order, SoldTo and PostalCode were not null, if any of them were you would get a Null Reference Exception. To handle this in the past we would have to create an if statement to check each part to see if it’s null before we try to trim the postal code.

In C# 6.0 we can solve this problem using the Null Reference Operator which makes for much cleaner code.

string zip = order?.SoldTo?.PostalCode?.Trim();

The question mark after each part is the null reference operator. When the code is being executed, if the part before the question mark is null execution of the line will end and null will be returned. So if order, SoldTo or PostalCode is null, zip will be set to null without an exception being thrown. If order and SoldTo both had values and PostalCode was null the null reference operator after PostalCode will prevent Trim from throwing and exception. As soon as the program sees that PostalCode is null it will skip the attempt to execute Trim().

You can also use this on arrays and collections like this…

List<SalesOrder> orders = null; 
order = orders?[1];

If the null reference operator was not used in the second line, this would throw a null reference exception because orders is null. With the operator the order variable will be set to null.

When new features like this are added to the language I always like to take a look at a disassembly of the code to see how the features are implemented. Nothing too surprising here, it’s done pretty much how we would have done it before this feature was added. Note that each part of the assignment is assigned to a variable before the null check is done. This is done in case there is a function call so it doesn’t get called more then once.

    if (salesOrder != null)
    {
        Address soldTo = salesOrder.SoldTo;
        if (soldTo != null)
        {
            string postalCode = soldTo.PostalCode;
            if (postalCode != null)
            {
                str = postalCode.Trim();
            }
            else
            {
                str = null;
            }
        }
        else
        {
            str = null;
        }
    }
    else
    {
        str = null;
    }

Saturday, May 30, 2015

Windows Live Writer Problem

Ever since I have been doing my blogs on Blogger.com I have been using Windows Live Writer as my editor. It integrated nicely with Blogger and the PreCode plugin made it really easy to add code snippets to the posts. Every thing was great until last week when I started getting an "Invalid Username or Password" error every time I tried to connect to Blogger from Live Writer.


A quick search of the Blogger and Microsoft support forums revealed that I wasn't the only one having this problem. It turns out the Google recently changed how external application authenticate when they connect to Blogger and even though they announced they would be making this change a while back Microsoft never updated Blogger. Initially the responses from both side blamed the other, but according to recent Twitter post by Scott Hanselman both companies are now working together on a fix that will be available "soon".
 
Update (6/2/2015): This problem has now been resolved. Thanks to Microsoft and Google for getting this issue resolved quickly.