You need to sign in to do that
Don't have an account?

Adding records from custom object to Campaign members list
I need to add community members of a community to the campaign members list.
I tried querying in my own way but i cound not execute successfully.
this was the error it was giving
Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Attempted to add a campaign member where either the member id 'null' or the campaign id 'null' is null.: []
I was not sure what is member id whether it is a contact id or community id or any other fields are missing..
I appreciate any help on this.
Thx
Hi,
can you please provide the code?
Thanks Vishal for ur reply.
Here is the code. Pls let me know
CreateCampignMembers(String SubscriptionID, Strign CampignID)
{
Subscription_Member__c[] SubscriptionMember_array = [Select id,Subscribed__c,Contact__c,Contact__r.HasOptedOutOfEmail from Subscription_Member__c where subscription__C='a0QT0000000ndaT' and Subscribed__c = true and Contact__r.HasOptedOutOfEmail = false ];
system.debug('size: ' + SubscriptionMember_array.size());
for (Subscription_Member__c sm:SubscriptionMember_array)
{
system.debug('Sub Mem id: ' + sm.id);
system.debug('Sub Mem Subscribed: ' + sm.Subscribed__c);
system.debug('Sub Mem HasOptedOutOfEmail: ' + sm.Contact__r.HasOptedOutOfEmail);
}
List <CampaignMember> CampaignMemberList = new List <CampaignMember>();
Campaign SelcCampaign = [Select id from Campaign where id='701T0000000Bw0m'];
Lead SelcLead = [Select id from Lead where id='00QT00000092xpB'];
Contact SelcContact = [Select id,AccountId,Birthdate,Department,Description,Email,Fax,FirstName,LastName,MailingCity,MailingCountry,MailingPostalCode,MailingState,MailingStreet,MobilePhone,Name,OtherCity,OtherCountry from Contact where id='003T000000yTmZr'];
//Integer CampignIterator = 0;
//Id campID = Camp_Array[CampignIterator].Id;
CampaignMember CampMeb;
/*for (Subscription_Member__c sma:SubscriptionMember_array)
{
system.debug(' END of the script :: In the Loop :: Start ');
CampMeb = new CampaignMember(Campaign=SelcCampaign,Contact=SelcContact,Status='Sent');
system.debug(' END of the script :: In the Loop ');
//CampaignMember CampMeb = new CampaignMember(Campaign='701T0000000Bw0m',Contact=sma.Contact__c);
CampaignMemberList.add(CampMeb);
}
//insert CampaignMember_array;
//insert CampMeb; */
CampMeb = new CampaignMember(Campaign=SelcCampaign,Contact=SelcContact,Status='Sent', Lead =SelcLead);
//CampMeb = new CampaignMember(Campaign=SelcCampaign,Status='Sent');
insert CampMeb;
system.debug(' END of the script ');
}
In order to be saved Campaign member must have :
CampaignId=Campaign.Id
LeadId=Lead.Id
or
CampignId=Campaign.Id
ContactId=Contact.Id
Campaign Member Fields
These are the fields (in alphabetical order) that make up a campaign member. Most campaign member fields are derived from the lead or contact record from which the campaign member was created and must be edited from the corresponding lead or contact record. Some of these fields may not be visible or editable depending on your page layout and field-level security settings. (Field-level security is available in Enterprise, Unlimited, and Developer Editions only.)
Field Description