To create static marketing list and associated marketing list member in Dynamics CRM 2011 below are the steps:
- Create the array of contacts/accounts/leads.
- Set type attribute as false to create static list.
- Make sure createdfromcode attribute is set as contact/account/lead optionset value.
- First create marketing list and then create associated marketing list member.
private void CreateList(Guid[] contactIds, IOrganizationService service)
{
Entity obj = new Entity("list");
obj.Attributes["listname"] = "Non-Responded Marketing list";
obj.Attributes["type"] = false; // false for static marketing list
obj["createdfromcode"] = new OptionSetValue(2); // Contact optionset value is 2
obj.Attributes["membertype"] = 2; // Contact type is 2
Guid listid = service.Create(obj);// Create marketing list
// Send request to create marketing list member for above created marketing list
AddListMembersListRequest AddMemberRequest = new AddListMembersListRequest();
AddMemberRequest.ListId = listid; // above created marketing list id
AddMemberRequest.MemberIds = contactIds;
AddListMembersListResponse AddMemberResponse = service.Execute(AddMemberRequest) as AddListMembersListResponse;
}