Tuesday, May 26, 2015

Prevent Campaign Member Deletion

We've begun integrating email blasts from Responsys into our Salesforce org at Lakeshore[1. I'm no longer with Lakeshore. I'm at VIZIO, Inc. now.] so our sales reps have better visibility into how their contacts are being marketed to.

If it weren't for DBAmp from forceAmp, this might have been a really tough project... But, with the magic of a few SQL queries, I was able to get it working just the way we wanted it to.

But that's not what this post is about[2. I probably could write an entire post just on DBAmp. It's a totally awesome product.].

One of the things I don't like about the Salesforce Campaign/Campaign Member hierarchy is even though a user is granted Read Only permission on the Campaign object, they can still delete any Campaign Member for Leads or Contacts they have Read/Write access to, and there's no real way to configure Salesforce to prevent it.

Here's a simple hack I used to prevent Campaign Member deletion. Credit for it goes entirely to Chris Lance on the Success Community.

First, create a new Visualforce page that will be used to block Campaign Member deletion. The code below looks an awful lot like the standard Insufficient Privileges page a user gets when they're not allowed to perform an action.


<apex:page standardController="CampaignMember" standardStylesheets="true">
<apex:form >
<table cellspacing="10">
<tr>
<td><span style="font-weight: bold; font-size: 12pt;">Insufficient Privileges</span></td>
</tr>
<tr>
<td>You do not have the level of access necessary to perform the operation you requested. Please contact your administrator if access is necessary.<br/></td>
</tr>
<tr>
<td><apex:commandLink action="{!cancel}" immediate="true" value="Return to previous page."/></td>
</tr>
</table>
</apex:form>
</apex:page>


Then, in the Campaign Member object (Setup > Build > Customize > Campaigns > Campaign Members > Buttons and Links), override the "Delete" button with the Visualforce page you just created.

Campaign Member Delete Override

Finally, rejoice that Campaign Members can no longer be deleted[3. Much rejoicing was had by all in this case...].

Prevent Campaign Member Deletion

Of course, there is a limitation to this hack in that nobody can delete Campaign Members, even the System Administrator.

For our needs, this is fine since we're integrating from an outside system. If certain profiles did need to delete, I might add some logic to the Visualforce page that lets them perform the action instead of being told they don't have the privilege.

4 comments:

  1. i created a 'marketing' user in salesforce but they cannot add members to a campaign they created - it gives the 'insufficient priv's' error

    do you know what i can do

    ReplyDelete
  2. @Christian... Take a look at this Answers post. It might be your solution: http://sforce.co/1JhMN8x

    Let me know if it helps.

    ReplyDelete
  3. Best Primavera P6 training institute chennaiDecember 20, 2015 at 7:24 PM

    That was really excellent news to read

    ReplyDelete
  4. Best Primavera P6 training institute chennaiDecember 22, 2015 at 7:29 PM

    That was great information to view that page

    ReplyDelete