function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
skodisanaskodisana 

How to Pass Campaign Member Id to the Force.com Sites URL

Hi,

 

I want to update the Campaign Member Status using the Force.com Sites. I just want ot know how i can pass the Campaign Member Id the Force.comSites URL. I have written one Custom Controller which will update the Camapign Status. Here i hardcoded the Campaign Member. Please suggest me how to pass theCampaign Member Id to the Sites URL.

 

Ex Site URL:http://Mysites-developer-edition.na6.force.com/test?id=701800000009EWSX

 

"701800000009EWSX" This isCampaign Member Id.

 

 

Thanks

Srikanth.K

 
Best Answer chosen by Admin (Salesforce Developers) 
jkucerajkucera

Skodisana - don't give up hope just yet ;)  Campaign Member, though it is a standard object, is the ONLY exception to the rule.

 

You can create public sites pages that directly edit/update the Campaign Member object.  Combined with campaign member custom fields (to be released mid July), this is a perfect combo for event registration pages. 

 

But don't take my word for it - check out my live example:

 

http://jdk470.force.com/?id=00v3000000JIrl6AAD

 

A couple more ID's you can change:

  • 00v3000000Jp9Ep 
  • 00v3000000KsPdo

 

Note I haven't yet included filters to determine the allowable status values for a campaign as most people will want to create Status as a hidden field & define a default value.  The real power here is with Campaign Member custom fields.

 

Mid July, look for Campaign member custom fields, which make this a lot more interesting.

 

Tips when setting up your Campaign Member sites pages:

  • Need Read on Campaign, and Read on Leads (if a lead) or Read on Contacts (if a Contact campaign member)
  • Sharing cannot be private, or the campaigns & leads/contacts must be explicitly shared with the  Guest User License profile


PS - there's a good chance I'll change / break the above link at some point in the future, but rest assured this works. 

Some code to get you started:

 

Apex Controller:

 

public class UpdateCampaignMemberClass{

public final CampaignMember cm;

private ApexPages.StandardController cmController;

public UpdateCampaignMemberClass(ApexPages.StandardController controller) {
cmController = controller;
this.cm= (CampaignMember)controller.getRecord();
}

public PageReference updatecm() {
try{
update cm;
}
catch(DmlException ex){
ApexPages.addMessages(ex);
}
Id = :cmid limit 1];

return new PageReference('');
}
public string getStatus(string Status){

where Id = :cmid limit 1];
return 'Status';
}

}

 VisualForce Page:

 

<apex:page standardController="CampaignMember" extensions="UpdateCampaignMemberClass" sidebar="false" showHeader="false">

<script type="text/javascript">

function getQueryVariable(variable) {
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if (pair[0] == variable) {
return pair[1];
}
} }

function showAlert(variable){
alert(variable);
}
</script>

<table align="center" bgcolor="#ffffff" border="0" cellpadding="0" cellspacing="0" width="800">
<tbody>
<tr>
<td align="left" height="60" valign="top">
<p>
<!--<apex:image id="CloudForceTop" value="{!$Resource.CloudforcebannerGIF}" width="800" height="150"/>
-->
</p>
<table align="center" border="0" cellpadding="0" cellspacing="0" width="760">
<tbody>
<tr>
<td colspan="2" height="60"><strong><font color="#d76d43" face="Arial, Helvetica, sans-serif" size="5">Sign up for our Customer Conference! </font></strong></td>
</tr>
<tr>
<td height="130" valign="top" width="450"><font face="Arial, Helvetica, sans-serif" size="2"><strong><font size="3">Learn best practices from customers like yourself.</font></strong><br/>
At this conference you'll meet like minded collegues with similar
issues. We'll have a host of sessions catered to your individual needs.
This will be the biggest and best event we've had yet and expect top
thought leaders such as Bill Gates and Warren Buffet discuss the state
of the economy and how you can mitigate risk.</font></td>
<td rowspan="2" align="center" valign="top"> <!--<apex:image id="EventCustomoreQuote" value="{!$Resource.EventCustomerQuote}" width="185" height="133"/>
<apex:image id="EventCustomerQuote2" value="{!$Resource.EventCustomerQuote2}" width="185" height="155"/>
-->
</td>
</tr>
<tr>
<td align="center" valign="top">
<apex:form >

<table border="0" width="500">
<tbody>
<tr>
<td>
<div align="right"><strong><font face="Arial, Helvetica, sans-serif" size="2"><label for="CMID" style="font-size: 14px;">Campaign Member ID</label>
</font></strong></div>
</td>
<td>&nbsp;</td>
<td><apex:Outputfield value="{!campaignmember.Id}"/></td>
</tr>
<tr>
<td>
<div align="right"><strong><font face="Arial, Helvetica, sans-serif" size="2"><label for="first_name" style="font-size: 14px;">First Name</label>
</font></strong></div>
</td>
<td>&nbsp;</td>
<td><apex:InputField value="{!campaignmember.Lead.FirstName}"/><apex:InputField value="{!campaignmember.Contact.FirstName}"/></td>
</tr>
<tr>
<td>
<div align="right"><strong><font face="Arial, Helvetica, sans-serif" size="2"><label for="Last_name" style="font-size: 14px;">Last Name</label>
</font></strong></div>
</td>
<td>&nbsp;</td>
<td><apex:InputField value="{!campaignmember.Lead.LastName}"/><apex:InputField value="{!campaignmember.Contact.LastName}"/></td>
</tr>
<tr>
<td>
<div align="right"><strong><font face="Arial, Helvetica, sans-serif" size="2"><label for="Status" style="font-size: 14px;">Status</label>
</font></strong></div>
</td>
<td>&nbsp;</td>
<td><apex:inputfield value="{!campaignmember.Status}"/></td>
</tr>
<tr>
<td>
<div align="right"><strong><font face="Arial, Helvetica, sans-serif" size="2"><label for="Hotel" style="font-size: 14px;">Hotel</label>
</font></strong></div>
</td>
<td>&nbsp;</td>
<!-- <td><apex:inputfield value="{!campaignmember.Hotel__c}"/></td>
</tr>
<tr>
<td>
<div align="right"><strong><font face="Arial, Helvetica, sans-serif" size="2"><label for="MealPreference" style="font-size: 14px;">Meal Preference</label>
</font></strong></div>
</td>
<td>&nbsp;</td>
<td><apex:inputfield value="{!campaignmember.Meal_Preference__c}"/></td>
</tr>
<tr>
<td>
<div align="right"><strong><font face="Arial, Helvetica, sans-serif" size="2"><label for="Registered" style="font-size: 14px;">Registered</label>
</font></strong></div>
</td>
<td>&nbsp;</td>
<td><apex:inputfield value="{!campaignmember.Registered__c}"/></td>
-->
</tr>
<tr>
<td>
</td>
<td>&nbsp;</td>
<td><apex:commandButton value="Register Now!" action="{!updatecm}" /></td>
</tr>
</tbody>
</table>

</apex:form>

</td>
</tr>
</tbody>
</table>

<!-- <apex:image id="CloudForceBottom" value="{!$Resource.CloudforcebottomGIF}" width="800" height="250"/>
-->
</td>
</tr>
</tbody>
</table>
</apex:page>

 The page looks a bit messy with all the tables for alignment, but does the trick.  Note I've commented out the pictures & a few other fields.

 

 

 

Message Edited by jkucera on 06-08-2009 09:23 PM

All Answers

BulentBulent
Sites license doesn't allow update and delete on standard objects
jkucerajkucera

Skodisana - don't give up hope just yet ;)  Campaign Member, though it is a standard object, is the ONLY exception to the rule.

 

You can create public sites pages that directly edit/update the Campaign Member object.  Combined with campaign member custom fields (to be released mid July), this is a perfect combo for event registration pages. 

 

But don't take my word for it - check out my live example:

 

http://jdk470.force.com/?id=00v3000000JIrl6AAD

 

A couple more ID's you can change:

  • 00v3000000Jp9Ep 
  • 00v3000000KsPdo

 

Note I haven't yet included filters to determine the allowable status values for a campaign as most people will want to create Status as a hidden field & define a default value.  The real power here is with Campaign Member custom fields.

 

Mid July, look for Campaign member custom fields, which make this a lot more interesting.

 

Tips when setting up your Campaign Member sites pages:

  • Need Read on Campaign, and Read on Leads (if a lead) or Read on Contacts (if a Contact campaign member)
  • Sharing cannot be private, or the campaigns & leads/contacts must be explicitly shared with the  Guest User License profile


PS - there's a good chance I'll change / break the above link at some point in the future, but rest assured this works. 

Some code to get you started:

 

Apex Controller:

 

public class UpdateCampaignMemberClass{

public final CampaignMember cm;

private ApexPages.StandardController cmController;

public UpdateCampaignMemberClass(ApexPages.StandardController controller) {
cmController = controller;
this.cm= (CampaignMember)controller.getRecord();
}

public PageReference updatecm() {
try{
update cm;
}
catch(DmlException ex){
ApexPages.addMessages(ex);
}
Id = :cmid limit 1];

return new PageReference('');
}
public string getStatus(string Status){

where Id = :cmid limit 1];
return 'Status';
}

}

 VisualForce Page:

 

<apex:page standardController="CampaignMember" extensions="UpdateCampaignMemberClass" sidebar="false" showHeader="false">

<script type="text/javascript">

function getQueryVariable(variable) {
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if (pair[0] == variable) {
return pair[1];
}
} }

function showAlert(variable){
alert(variable);
}
</script>

<table align="center" bgcolor="#ffffff" border="0" cellpadding="0" cellspacing="0" width="800">
<tbody>
<tr>
<td align="left" height="60" valign="top">
<p>
<!--<apex:image id="CloudForceTop" value="{!$Resource.CloudforcebannerGIF}" width="800" height="150"/>
-->
</p>
<table align="center" border="0" cellpadding="0" cellspacing="0" width="760">
<tbody>
<tr>
<td colspan="2" height="60"><strong><font color="#d76d43" face="Arial, Helvetica, sans-serif" size="5">Sign up for our Customer Conference! </font></strong></td>
</tr>
<tr>
<td height="130" valign="top" width="450"><font face="Arial, Helvetica, sans-serif" size="2"><strong><font size="3">Learn best practices from customers like yourself.</font></strong><br/>
At this conference you'll meet like minded collegues with similar
issues. We'll have a host of sessions catered to your individual needs.
This will be the biggest and best event we've had yet and expect top
thought leaders such as Bill Gates and Warren Buffet discuss the state
of the economy and how you can mitigate risk.</font></td>
<td rowspan="2" align="center" valign="top"> <!--<apex:image id="EventCustomoreQuote" value="{!$Resource.EventCustomerQuote}" width="185" height="133"/>
<apex:image id="EventCustomerQuote2" value="{!$Resource.EventCustomerQuote2}" width="185" height="155"/>
-->
</td>
</tr>
<tr>
<td align="center" valign="top">
<apex:form >

<table border="0" width="500">
<tbody>
<tr>
<td>
<div align="right"><strong><font face="Arial, Helvetica, sans-serif" size="2"><label for="CMID" style="font-size: 14px;">Campaign Member ID</label>
</font></strong></div>
</td>
<td>&nbsp;</td>
<td><apex:Outputfield value="{!campaignmember.Id}"/></td>
</tr>
<tr>
<td>
<div align="right"><strong><font face="Arial, Helvetica, sans-serif" size="2"><label for="first_name" style="font-size: 14px;">First Name</label>
</font></strong></div>
</td>
<td>&nbsp;</td>
<td><apex:InputField value="{!campaignmember.Lead.FirstName}"/><apex:InputField value="{!campaignmember.Contact.FirstName}"/></td>
</tr>
<tr>
<td>
<div align="right"><strong><font face="Arial, Helvetica, sans-serif" size="2"><label for="Last_name" style="font-size: 14px;">Last Name</label>
</font></strong></div>
</td>
<td>&nbsp;</td>
<td><apex:InputField value="{!campaignmember.Lead.LastName}"/><apex:InputField value="{!campaignmember.Contact.LastName}"/></td>
</tr>
<tr>
<td>
<div align="right"><strong><font face="Arial, Helvetica, sans-serif" size="2"><label for="Status" style="font-size: 14px;">Status</label>
</font></strong></div>
</td>
<td>&nbsp;</td>
<td><apex:inputfield value="{!campaignmember.Status}"/></td>
</tr>
<tr>
<td>
<div align="right"><strong><font face="Arial, Helvetica, sans-serif" size="2"><label for="Hotel" style="font-size: 14px;">Hotel</label>
</font></strong></div>
</td>
<td>&nbsp;</td>
<!-- <td><apex:inputfield value="{!campaignmember.Hotel__c}"/></td>
</tr>
<tr>
<td>
<div align="right"><strong><font face="Arial, Helvetica, sans-serif" size="2"><label for="MealPreference" style="font-size: 14px;">Meal Preference</label>
</font></strong></div>
</td>
<td>&nbsp;</td>
<td><apex:inputfield value="{!campaignmember.Meal_Preference__c}"/></td>
</tr>
<tr>
<td>
<div align="right"><strong><font face="Arial, Helvetica, sans-serif" size="2"><label for="Registered" style="font-size: 14px;">Registered</label>
</font></strong></div>
</td>
<td>&nbsp;</td>
<td><apex:inputfield value="{!campaignmember.Registered__c}"/></td>
-->
</tr>
<tr>
<td>
</td>
<td>&nbsp;</td>
<td><apex:commandButton value="Register Now!" action="{!updatecm}" /></td>
</tr>
</tbody>
</table>

</apex:form>

</td>
</tr>
</tbody>
</table>

<!-- <apex:image id="CloudForceBottom" value="{!$Resource.CloudforcebottomGIF}" width="800" height="250"/>
-->
</td>
</tr>
</tbody>
</table>
</apex:page>

 The page looks a bit messy with all the tables for alignment, but does the trick.  Note I've commented out the pictures & a few other fields.

 

 

 

Message Edited by jkucera on 06-08-2009 09:23 PM
This was selected as the best answer
XKennanXKennan

I love the demo.  I've got it working.  There's only one small issue, how do I redirect the user to a 'thank you' page once they submit?  I don't understand the updatecm method.  Can you point me to some documentation on how I can pass a reference to another page back to the visualforce page?

 

X

jkucerajkucera

Page references returned to the VF page set the active URL.  Change this line in the controller to the URL you want to redirrect to:

 

Before

 return new PageReference('');

 After

 return new PageReference('www.google.com');
XKennanXKennan

Do I have to set redirect to 'true'?

 

X

jkucerajkucera

No - it automatically changes the page when that action/method is called. 

 

I'll be posting a similar method for encrypting sites pages on my blog shortly.  This does the same page reference change if the URL isn't exactly as expected. 

HarryBHarryB

Seems this is not working anymore, including the demo. All I get is "Autorization required" after hitting the "send" button, which indicates an apex exception.

 

So this leads me to the conclusion that the exception of CampaignMember to the rule "No update on standard objects" has been removed.

 

Any ideas?

 

Regards,

Harry

NaweNawe

Hi - I'm failing to use the above but am dying to have the ability to send invitations to existing Contacts, and Leads who we are targeting for an event that have one button that they can click on in an email template that changes their Campaign Member Status to ‘Registered Interest’ (standard campaign member status we have on all our marketing events in Salesforce).

 

Note these are people we already know about that we'd be targeting and not new leads (i.e. web-to-lead is only going to cause duplication issues so do not want to use this functionality).

 

Any advice on how to implement the above?

 

Many thanks,

 

Ewan

JuulJuul

What do I need to change in the code to only show the status values for the current campaign.

In my testpage I see all possible status values ever created! 

 

The next question is answered but I don't know how to redirect to the thank you page after pressing update.

 

Do I need to change "UpdateCampaignMemberClass"?

 

return new PageReference('http://MYNAME.force.com/testt/?id=' + cm.id );
} public string getStatus(string Status){
return 'Status';
}