You need to sign in to do that
Don't have an account?
Can I update Campaign Member Status with Apex ?
Hi all,
I'm trying to update campaign member status with Apex.
I created Visualforce page.
In save() method, I tried to update campaign member status.
Here is my code.
//current value CampaignMemberStatus oldDefault = [select Id from CampaignMemberStatus where CampaignId = :currentId and isDefault = true LIMIT 1]; CampaignMemberStatus oldRespond = [select Id from CampaignMemberStatus where CampaignId = :currentId and HasResponded = true LIMIT 1]; //update label (It's a default) CampaignMemberStatus oldstatus = new CampaignMemberStatus( Id = oldDefault.Id, Label = 'entry'); update oldstatus; //change sortorder (It's hasResponded) CampaignMemberStatus oldorder = new CampaignMemberStatus( Id = oldRespond.Id, SortOrder = 3); update oldorder; //add attend CampaignMemberStatus newstatus = new CampaignMemberStatus( CampaignId = currentId, Label = 'attend', SortOrder = 2, isDefault = false, HasResponded = false); insert newstatus;
I can change SortOrder and insert attend(not default and not hasresponded value).
But I can't update the default's label.
Is it impossible?
How can I do?
Any solution to this problem is greatly appreciated.
astraea
Not sure if it would directly solve your issue, but I created an Apex trigger in our system that completely deletes all Campaign Member Status values from a Campaign and then rebuilds the values with our approved list. It runs whenever a Campaign is created or cloned, so all new Campaigns have the same set of approved status values.
It also has some additional statements at the beginning that change whether a status counts as a response based on what type of Campaign it was. Those need to run when the Campaign is updated and the Lead Source field changes. For example, we have an Unable to Reach status. For a direct mail Campaign, this is still a response, because they responded to the Campaign and we just weren't able to follow up on the phone. For outbound telemarketing, it's not a response, because we never connected with them. So, basically the code looks more complex than it needs to because of our customizations. If you can get past them, the later part of the code wipes out the defaults statuses and rebuilds.
We also have a basic test class for this, but note that it refers to a constant class that we maintain to simplify future updates.