2

For the past year+ I have been adding a Lead to a Campaign through the API using code like this:

SForceService binding = GetBinding();
var cmp = new CampaignMember { CampaignId = campaignId, LeadId = leadId, HasResponded = false };
var result = binding.create(new sObject[] {cmp});

This has worked fine, with no issues.

This morning at approximately 10:00 UTC I started getting the following error message back when trying to do this:

entity type cannot be inserted: Campaign Member

The only thing I could get through Google is that this is the type of error message that you get when you try to insert an object into a ReadOnly collection (for example: ActivityHistory). However, CampaignMember seems to definitely not be a readonly object, since it is used to define the relation of other objects to Campaigns.

So I am at a loss as to what could lead to this. No changes have been made to our local code in this area, I have verified that the CampaignId being used is for an Active campaign in SF (also unchanged), and we haven't made any other changes to our SF setup recently.

Does anyone know:

  1. Is there a good explanation for why I would begin to receive this error?
  2. Is there some way I can change my code to make this work, or is there some other way to associate a Lead (or other object) with a Campaign through the API?
  • If it used to work and now it doesn't, I would recommend logging in and manually trying to create the Campaign Member to ensure that something hasn't changed with security or a validation rule. Also ensure that the user still have the 'Marketing User' checkbox on the user. – Eric Clay Dec 3 '15 at 20:50
  • @EricClay we can still manually assign leads to the campaign online. The API user is a SysAdmin, has never had MarketingUser set, but we are going to try that right now – Yaakov Ellis Dec 3 '15 at 20:51
1

I feel like some bug was introduced this morning. Another user posted a similar problem: Error creating Campaign Member from flow and I think my issue may be related as well:

I have a Force.com site with a Visualforce page that has contact as well as campaignmember fields. Suddenly today, I am getting the following error:

system.security.NoAccessException: Create access denied for CampaignMember, controller action methods may not execute

This happened simultaneously on both Sandbox and Production.

  • confusingly, the doc says only upsert may be used after V16.0 - but that is hard to believe – cropredy Dec 3 '15 at 23:09
0

any chance you're trying to insert the CampaignMember as logged in as a Customer Portal user? They don't have access.

  • No. It is using an API user with lots of privileges (is also used to insert the very same Lead being associated with the Campaign five lines of code above). And up until this morning, the same setup was working just fine, and we didn't make any changes to our setup. – Yaakov Ellis Dec 3 '15 at 20:39
  • Just checked - the API user has System Admin rights. – Yaakov Ellis Dec 3 '15 at 20:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.