• PrK
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
I would like to remove primary campaign source from the contact and opportunity on lead conversion unless the lead had Responded to the campaign.  

I tried this trigger, but it doenst work, and i cant figure out why

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);
}
}



}