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
MLamb2005MLamb2005 

Query and update Campaign Member

Hi all,

 

I've got some Campaign Member custom fields that I'm trying to update with a VisualForce page.  The page exists to receive a URL, which consists of a Campaign Member ID and a flag to tell me which field to update.

 

I am able to query the Campaign Member table, find the right Campaign Member, but then when it comes to making the actual data update, I keep getting an Authorization Required page and nothing actually updates.

 

The relevant part of my code is below, any ideas?

 

public without sharing class ControllerWebIQUpdate { public string campaignMemberID{get;set;} public string progressType{get;set;} public string textDisplay{get;set;} public string gettextDisplay(){ return textDisplay; } public ControllerWebIQUpdate(){ PageReference pr = System.currentPageReference(); campaignMemberID = System.currentPageReference().getParameters().get('cmid'); progressType = System.currentPageReference().getParameters().get('ft'); if(campaignMemberID == null){ //Error condition, don't have a 'cmid' value, do something textDisplay = 'Didnt get a CMID'; } else{ CampaignMember testCM = new CampaignMember(); List<CampaignMember> listCM = [Select Passed_Screener__c, Completed__c From CampaignMember Where Id = : campaignMemberID]; if(listCM.size() == 1){ textDisplay = 'Found the CM!'; if(progressType == 'screener'){ testCM = listCM.get(0); testCM.Passed_Screener__c = true; update testCM; textDisplay = 'Passed the screener!'; } else if(progressType == 'completed'){ testCM = listCM.get(0); testCM.Completed__c = true; update testCM; textDisplay = 'Finished the survey!'; } else{ textDisplay = 'Something was wrong with the FT parameter'; //Error condition, incorrect 'ft' value, do something } } else{ textDisplay = 'This shouldnt happen, bad news.'; //Error condition, something went wrong with the CampaignMember query } } } }

 

 

Best Answer chosen by Admin (Salesforce Developers) 
MLamb2005MLamb2005
Fixed, for anyone who finds this thread, I couldn't run this code from my Constructor.  I had to put it in it's own function and add the action={!<call>} code to my VisualForce page.

All Answers

MLamb2005MLamb2005
Fixed, for anyone who finds this thread, I couldn't run this code from my Constructor.  I had to put it in it's own function and add the action={!<call>} code to my VisualForce page.
This was selected as the best answer
Rachel van den Berg 1Rachel van den Berg 1
I know this is a very old question but I am actually running into the same issue and do not fully get the solution provided. Is anyone able to share the solution for this?