Wednesday, January 9, 2013

Setting a limit for number of campaign members

Limiting the number of campaign members in Salesforce might come in handy in many situations. We are habitually organizing seminars and other customer events where we can only have a limited number of attendees. Normally there is no way of setting a maximum number of people that can be invited to a campaign so I was given a task to figure out a way of doing it.

We specifically wanted to track the number of people with the status "Attending" so that Salesforce would warn us when we are trying to add more people than there is actually room for. We also arrange some events where people are allowed to bring a colleague or any other avec so in this post we will consider that as well. But to get things working we needed a couple of things:

"Maximum number of attendees" field

This one goes straight in to the Campaign object. It's just a normal number field and we can input the number of available spots in there. If it is left blank then there are no limitations on the campaign.

Counting the attendees

We are using standardized campaign member values and it really helps in creating numeric values from the member statuses by using the CASE function. It is important to have standardized member statuses if you are doing it like this because the case function checks the exact value of the Status field and gives different values depending on the status.

In our seminars and some special events we have campaign member statuses "Attending" and "Attending + avec" and we need to translate those in to numbers so that the standard roll-up function can summarize them. So for this we need to go to the Campaign member object and create a number field with the following formula:  
CASE( Status , "Attending", 1, "Attending + avec", 2, 0)
This formula first checks if the Status is "Attending" and gives the value 1 for those. Then it checks if the value is "Attending + avec" and gives the value 2 for those. Else it's just 0.

If you don't have the need to reserve two seats for one invitee you can just use CASE( Status , "Attending", 1, 0) as the formula. That will most likely be enough for most organizations.
This field doesn't need to be visible because mainly we will be using it to do the roll-up summary.

Creating the roll-up summary

Now that we have a field in the campaign member object that shows a number if the person is attending (or two if they are attending with an avec) we can move on. So we go go back to the Campaign object and create a Roll-up summary field that sums the values of our newly created field.

I named this field Attendees so in the validation rule it will show as Attendees__c. This field is nice to have on the page layout because it gives us the relevant information on how many people have signed up with a simple glance.

Creating the validation rule for maximum attendees.

The help text that Salesforce tells you on top of the validation rule is not very clear. Technically "If this formula expression it true, display the text defined in the Error Message area" is correct but I find it a bit confusing at times. Instead I tend to start the thought process with the words "It should give you an error message if..." and the right form of validation rule comes quite naturally.

So in this case it should give you an error message if the number of attendees is higher than the maximum number of attendees.
Attendees__c > Max_number_of_attendees__c 
And we are done! Now the system will inform us if we are trying to overbook the event. You might want to set the maximum number of attendees to be slightly lower than it really is at first so you get notified before you hit the limit. Or if you are expecting no-shows it can be slightly larger. I guess common sense and experience will be good tools to evaluate the number here.

The solution that I ended up with might not be the most elegant but it can be done without any code and it has served us well. If you have a simpler way of achieving this I'd love to hear about it!

No comments:

Post a Comment