If you’ve ever used the members of a Salesforce Campaign to create a list with
VerticalResponse, then you probably know that we can update your Campaign Member Analysis Report with stats showing Opens, Clicks, Bounces and Unsubscribes. And if you know that, then you probably also know that you have to manually edit your Campaign Member Status Values for each Salesforce Campaign to add values of Opened, Clicked, Bounced and Unsubscribed in order to see these stats in your report. This step can be an easy one to forget.
Do you wish there was a way you could automatically populate your Member Status Values with the necessary values? Well, you’re in luck! Because in today’s blog post, we’re going to look at how you can do this.
Several blog posts ago, I showcased a trigger created by Dave Manelski of onenw.org that made it easier to mark Lead & Contact records as bounced. That trigger was so helpful, that today I’m showcasing a trigger he’s written that will do just what I’ve described above: automatically populate any Campaign you create with a Type of “VR Email” with the necessary Opened, Clicked, Bounced, and Unsubscribed values.
Before you can put Dave’s trigger to use, you should be sure that:
1. You’ve created a VR Email Campaign type. To do this, you go to:
Setup > Campaigns > Fields > Edit Type > New
2. You’re an admin and you know where to create new Campaign Triggers:
Setup > Campaigns > Triggers > New
I’ll let Dave introduce his code:
This trigger automatically sets the Campaign Member Status of a Salesforce
Campaign to Sent, Opened, Clicked, and Unsubscribed when the campaign is
of the Type 'VR Email'. This ensures that when you Update Statistics
from VR that the Contact record is updated correctly, and takes out the
step of having to manually set the Salesforce campaign member status to
match the VR statuses.
Here's the trigger:
// Written by David Manelski, copyright (c) 2008 ONE/Northwest
// This program is released under the GNU General Public License. http://www.gnu.org/licenses
// In order for this code to work, Vertical Response from the AppExchange must be installed and
// correctly configured. Also, the Campaign Type VR Email must be created.
trigger ONEN_VR_Update_Campaign_Member_Status on Campaign (after insert) {
List<CampaignMemberStatus> newStatuses = new List<CampaignMemberStatus>();
for (Campaign thisCampaign : trigger.new) {
if ( thisCampaign.Type == 'VR Email' ) {
CampaignMemberStatus statusOne = new CampaignMemberStatus(
Label = 'Opened',
CampaignId = thisCampaign.id,
HasResponded = true,
SortOrder = 7
);
newStatuses.add(statusOne);
CampaignMemberStatus statusTwo = new CampaignMemberStatus(
Label = 'Clicked',
CampaignId = thisCampaign.id,
HasResponded = true,
SortOrder = 8
);
newStatuses.add(statusTwo);
CampaignMemberStatus statusThree = new CampaignMemberStatus(
Label = 'Unsubscribed',
CampaignId = thisCampaign.id,
HasResponded = true,
SortOrder = 9
);
newStatuses.add(statusThree);
}
}
insert newStatuses;
}
And here’s the test class:
// Written by David Manelski, copyright (c) 2008 ONE/Northwest
// This program is released under the GNU General Public License. http://www.gnu.org/licenses/
public class ONEN_Test_VR_Campaign_Member_Status {
public static testMethod void testONEN_VR_Campaign_Member_Status() {
// Insert a new campaign with VR Email type to test
Campaign newCampaign = new Campaign (
Name = 'New Campaign',
Type = 'VR Email'
);
insert newCampaign;
// Verify that the new Campaign Member Status 'Opened' has been created
CampaignMemberStatus newStatusOne = [select CampaignId, Label from CampaignMemberStatus where CampaignId = :newCampaign.id and Label = 'Opened' limit 1];
System.assertEquals('Opened', newStatusOne.Label);
// Verify that the new Campaign Member Status 'Clicked' has been created
CampaignMemberStatus newStatusTwo = [select CampaignId, Label from CampaignMemberStatus where CampaignId = :newCampaign.id and Label = 'Clicked' limit 1];
System.assertEquals('Clicked', newStatusTwo.Label);
// Verify that the new Campaign Member Status 'Unsubscribed' has been created
CampaignMemberStatus newStatusThree = [select CampaignId, Label from CampaignMemberStatus where CampaignId = :newCampaign.id and Label = 'Unsubscribed' limit 1];
System.assertEquals('Unsubscribed', newStatusThree.Label);
}
}
Try this out and let us know what you think in the comments! Just remember that, once this is setup, the proper Member Status Values will be automatically created only if you set your Campaign with a Type of “VR Email”.

Comments