You need to sign in to do that
Don't have an account?
Naveen Ashok Sirivella
Populate campaign details on lead record
Hi All,
I want to update campaign name,primary product on Lead record .
Please find the below code
Public static void After_UpdateLeadCampaignDetails()
{
List<CampaignMember> camlist = (List<CampaignMember>)trigger.new;
System.debug('Values in the camlist:========================>'+camlist);
Set<Id> leadid = new Set<Id>();
List<Lead> leadlist = new List<Lead>();
for(CampaignMember cm:camlist)
{
Lead lea = new Lead();
if(lea.id == cm.LeadId)
{
lea.Campaign_Name__c = cm.Campaign.name;
leadlist.add(lea);
}
}
database.update(leadlist);
}
Please help any one
I want to update campaign name,primary product on Lead record .
Please find the below code
Public static void After_UpdateLeadCampaignDetails()
{
List<CampaignMember> camlist = (List<CampaignMember>)trigger.new;
System.debug('Values in the camlist:========================>'+camlist);
Set<Id> leadid = new Set<Id>();
List<Lead> leadlist = new List<Lead>();
for(CampaignMember cm:camlist)
{
Lead lea = new Lead();
if(lea.id == cm.LeadId)
{
lea.Campaign_Name__c = cm.Campaign.name;
leadlist.add(lea);
}
}
database.update(leadlist);
}
Please help any one
Regards,
Pawan Kumar
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
I guess you may have triigger that somewhat looks like this
Please change the ,className to something you have.
trigger:
trigger CampaignMemberTrigger on CampaignMember (before insert,before update,before delete,after insert,
after update,after delete,after undelete)
{
TriggerRouter.Handler(new CamapignMemberHandeler());
}
Class
public class CampaignMemberHelper
{
Public static void After_UpdateLeadCampaignDetails()
{
List<CampaignMember> camlist = (List<CampaignMember>)trigger.new;
System.debug('Values in the camlist:========================>'+camlist);
Set<Id> leadid = new Set<Id>();
List<Lead> leadlist = new List<Lead>();
for(CampaignMember cm:camlist)
{
Lead le = new Lead (Id = cm.LeadId);
le.Campaign_Name__c = cm.Campaign.Name;
leadlist.add(le);
}
if(!leadlist.isEmpty())
{
System.debug('size of the leadlist:=============================================>'+leadlist.size());
database.update(leadlist);
}
}
}
and modified your code according to your comments but the campaign name is not updating on lead record
Can you please share the class CamapignMemberHandeler
---------------------
trigger CampaignMemberTrigger on CampaignMember (before insert,before update,before delete,after insert,
after update,after delete,after undelete)
{
TriggerRouter.Handler(new CamapignMemberHandeler());
}
campaign member
-------------------------------
public class CamapignMemberHandeler implements TriggerInterface
{
public void isActive()
{
}
public void beforeInsert()
{
}
public void beforeUpdate()
{
}
public void beforeDelete()
{
}
public void afterInsert()
{
}
public void afterUpdate()
{
CampaignMemberHelper.After_UpdateLeadCampaignDetails();
}
public void afterDelete()
{
}
public void afterUndelete()
{
}
}
helper
----------------------
public class CampaignMemberHelper
{
Public static void After_UpdateLeadCampaignDetails()
{
List<CampaignMember> camlist = (List<CampaignMember>)trigger.new;
System.debug('Values in the camlist:========================>'+camlist);
Set<Id> leadid = new Set<Id>();
List<Lead> leadlist = new List<Lead>();
for(CampaignMember cm:camlist)
{
Lead le = new Lead (Id = cm.LeadId);
le.Campaign_Name__c = cm.Campaign.Name;
leadlist.add(le);
}
if(!leadlist.isEmpty())
{
System.debug('size of the leadlist:=============================================>'+leadlist.size());
database.update(leadlist);
}
}
}
You haven't said what is the problem with your code. Please share the Trigger Interface code
trigger interface doesn't have any problem