You need to sign in to do that
Don't have an account?

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: Trigger.new) {
Lead l = [SELECT id,converteddate FROM Lead WHERE ConvertedOpportunityId =:o.ID LIMIT 1];
try {
if(l.converteddate!=null){
CampaignMember cm = [Select id,Status, HasResponded FROM campaignmember WHERE LeadId=:l.id AND CampaignId=:o.Campaign.id];
if (cm.HasResponded ==false){
o.CampaignId=null;
}
}
} catch (Exception e){
system.debug('error: ' +e);
}
}
}
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?