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

Strange new apex trigger error inserting campaign members



I have a trigger in production in over a dozen salesforce instances.  It's an after insert, after update trigger on Opportunity that inserts a campaign member record for the primary contact role if the opportunity has a Primary Campaign Source.


Up until Summer '09, the trigger was working fine but after upgrade starting throwing exceptions: 

caused by: System.DmlException: Insert failed. First exception on row 0; first error: DUPLICATE_VALUE, This entity is already a member of this campaign

Looks to me like inserting duplicate campaign members from a trigger now throws an exception.  This used to just fail gracefully and not do anything (i.e. no insert, no exception).  Could someone confirm that this is intended functionality? I know that I can always SOQL for existing campaign membership but that's an extra SOQL I'd prefer not to have to do. Just making sure this is intended an not a bug.





This is a new behavior; initially if you were trying to insert a member which alredy associated with the same campaign;

it was silently updating the status.

But now it is showing an error, so I think we have to run an extra SOQL or try upsert to mange this.



Rajan Jasuja



I am encountering this through campaign member  import wizard wizard. What is the workaround for this?

Denis M 7Denis M 7
Hello -

Would you mind sharing the final code that ended up working?