You need to sign in to do that
Don't have an account?
DUPLICATE_VALUE, This entity is already a member of this campaign: []
Hi,
I have to add the contacts to campaign members..
Here is my code.
public PageReference camprollup(){
list<CnP_Transaction__c> listtransactions = [selectName,Contact__c,sf_Campaign__c,Email__c,Donation_Name__c,Campaign__c fromCnP_Transaction__c where sf_Campaign__c!=null OR Campaign__c!=null];
for(CnP_Transaction__c lst : listtransactions){
Map_Camp_To_Contact_Id.put(lst.Id, lst.sf_Campaign__c);
CampaignList.add(lst.sf_Campaign__c);
EmailSet1.add(lst.Email__c);
OrdnumSet.add(lst.Id);
}
try{
if(!listtransactions.isEmpty()){
list<Campaign> listcampaign = [SELECT Id, Name FROM Campaign WHERE Id IN :CampaignList]; for(Campaign cn :listcampaign){
Map_Camp_Id.put(cn.Id, cn.Id);
}
List<CampaignMember> campmem = [select contact.Email,Campaignid,Contactid from CampaignMember where CampaignId!=null and CampaignId = :CampaignList];
for(CampaignMember cm :campmem){
Map_CamId_ConId.put(cm.CampaignId,cm.ContactId);
}
list<Contact> ContactMap1=[Select Id,Email,npo02__Household__c from Contact where Email IN :EmailSet1]; for(Contact k:ContactMap1){
Map_Contact_To_Id.put(k.Email,k.Id);
}
CampaignMember CreateMem=new CampaignMember();
for(Integer i = 0;i<listtransactions.size();i++){
if(listtransactions[i].sf_Campaign__c!=null && Map_Contact_To_Id.get(listtransactions[i].Email__c)!=null && Map_CamId_ConId.get(Map_Camp_Id.get(listtransactions[i].sf_Campaign__c))!=Map_Contact_To_Id.get(listtransactions[i].Email__c) ){
CreateMem = new CampaignMember(Campaignid=Map_Camp_Id.get(listtransactions[i].sf_Campaign__c), Contactid=Map_Contact_To_Id.get(listtransactions[i].Email__c), Status='Received'); Map_CamId_ConId.put(Map_Camp_Id.get(listtransactions[i].sf_Campaign__c), Map_Contact_To_Id.get(listtransactions[i].Email__c));//listtransactions[i].Contact__c); campmember.add(CreateMem);
}
}
if(!campmember.isEmpty()){
insert campmember;
}
Here when I'm getting Duplicate value of an entity error..
Can any one of you plz help me on this plz...
Anu.