I believe you are calling this method from the trigger.The issue with your code is you are referring trigger.new which is only available with trigger context. You also have some unnecessary code. Here is the simple code for your requirements Public static void After_UpdateLeadCampaignDetails(List<Id> idList)
{
List<CampaignMember> camlist = [Select Campaign.Name, LeadId From CampaignMember Where Id IN :idList];
System.debug('Values in the camlist:========================>'+camlist);
if(camlist == null) return;
List<Lead> leadToUpdateList = new List<Lead>();
for(CampaignMember cm:camlist)
{
Lead lead = new Lead (Id = cm.LeadId);
lead.Camapign_Name__c = cm.Campaign.Name;
leadToUpdateList.add(lead);
}
if(!leadToUpdateList.isEmpty())
database.update(leadlist);
}
I guess you may have triigger that somewhat looks like this
Please change the ,className to something you have.
trigger UpdateLeadCampaign on CampaignMember (after update) {
<className>.After_UpdateLeadCampaignDetails(trigger.new);
}
10 réponses