Skip to main content The Trailblazer Community will be unavailable from 2/1/2025 to 2/2/2025. Please plan your activities accordingly.
error

We made a wrong turn. Try again.

How do I show the campaign name in the opportunity record under lead information fields, Other fields that I wanted I mapped them and they are visible

Here, I want the campaign name to be in the lead information section on the opportunity page when the lead is converted

Any suggestions here
9 answers
  1. May 11, 2016, 7:41 PM
    Step 1: Create a custom field on the lead --> Campaign_Name__c

    Step 2:

    Create an Apex class to populate this^ field with Campaign Name

    public class CampmemTriggerhelper{

    public static void CampmemTrigger(list<CampaignMember> lstcmp){

    set<Id> leadIds=new set<Id>();

    list<Lead> lstleads=new list<Lead>();

    map<Id,string> mapLeadIdByCampaign=new map<Id,string>();

    for(CampaignMember c:[Select Id,LeadId,Campaign.Name from CampaignMember where ID IN:lstcmp]){

    leadIds.add(c.LeadId);

    mapLeadIdByCampaign.put(c.LeadId,c.Campaign.Name);

    }

    for(Lead l:[Select Id,Campaign_Name__c from Lead where Id in :leadIds]){

    if(l.Campaign_Name__c==null){

    if(mapLeadIdByCampaign.get(l.id)!=null){

    l.Campaign_Name__c=mapLeadIdByCampaign.get(l.id);

    }

    lstleads.add(l);

    }

    }

    update lstleads;

    }

    }

    Step 3: Create an Apex Trigger on Campaigns to call that^ class

    trigger CampmemTrigger on CampaignMember(after insert){

    CampmemTriggerhelper.CampmemTrigger(Trigger.new);

    }

    Step 4: Now that you have the Campaign Name field on Lead populating Campaign Name, use this field to map the field on Opportunity.

     
  2. May 12, 2016, 3:33 PM

    Replace

    CampmemTriggerhelper.C_CampaignMemberHandler(Trigger.new);

    with

    CampmemTriggerhelper.CampmemTrigger(Trigger.new);

    in you're Apex Trigger. Thank you !

     
0/9000