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

How to remove Primary Campaign Source on Opportunity if Campaign Member Responded is False

To share with the community a discussion I had with another customer, here's the basics for a trigger that checks the campaign member HasResponded field and changes the Opportunity Primary Campaign Source. 


This could modified for whatever criteria you want PrimaryCampaignSource to use.


trigger checkPrimaryCampaignSource on Opportunity (before update) {
for (Opportunity o: {
Lead l = [SELECT id,converteddate FROM Lead WHERE ConvertedOpportunityId =:o.ID LIMIT 1];
try {
CampaignMember cm = [Select id,Status, HasResponded FROM campaignmember WHERE AND];
if (cm.HasResponded ==false){
} catch (Exception e){
system.debug('error: ' +e);


Message Edited by jkucera on 12-21-2009 04:37 PM

The advice gets rid of the campaign for an opportunity.  I want to add a campaign to an opportunity and not have it be Primary.  How do I do that?  I tried this in VB.NET


Dim oSFOpportunity As sForce.Opportunity = oQR.records(0)

            oSFOpportunity.CampaignId = SCampaignID

            oSFOpportunity.Campaign_Primary__c = Nothing

 I see the new campaign linked to the Opportunity, but marked as Primary.  What should I do?