public static void RemoveFromMarketingList(Guid listMember, Guid listId) { RemoveMemberListRequest request = new RemoveMemberListRequest(); request.EntityId = listMember; request.ListId = listId; RemoveMemberListResponse response = XrmCore.Execute <RemoveMemberListRequest, RemoveMemberListResponse>(request); }
protected override void Execute(CodeActivityContext executionContext) { #region "Load CRM Service from context" Common objCommon = new Common(executionContext); objCommon.tracingService.Trace("Load CRM Service from context --- OK"); #endregion #region "Read Parameters" EntityReference marketingList = this.MarketingList.Get(executionContext); objCommon.tracingService.Trace(String.Format("marketingList: {0} ", marketingList.Id.ToString())); EntityReference account = this.account.Get(executionContext); EntityReference contact = this.contact.Get(executionContext); EntityReference lead = this.lead.Get(executionContext); #endregion Guid idToRemove = Guid.Empty; if (account != null) { idToRemove = account.Id; } else if (contact != null) { idToRemove = contact.Id; } else if (lead != null) { idToRemove = lead.Id; } objCommon.tracingService.Trace(String.Format("idToRemove: {0} ", idToRemove.ToString())); RemoveMemberListRequest removeRequest = new RemoveMemberListRequest(); removeRequest.ListId = marketingList.Id; removeRequest.EntityId = idToRemove; RemoveMemberListResponse removeResponse = (RemoveMemberListResponse)objCommon.service.Execute(removeRequest); }
public void UnsubscribeSubscribers(string ListId, List <Entities.Subscriber> subscribers) { try { Guid listGuid = new Guid(ListId); RemoveMemberListRequest req = new RemoveMemberListRequest(); req.ListId = listGuid; foreach (Entities.Subscriber subscriber in subscribers) { Contact contact = (Contact)context.ContactSet.Where(x => x.EMailAddress1.Equals(subscriber.E_mail)).FirstOrDefault(); if (contact != null) { req.EntityId = contact.Id; RemoveMemberListResponse resp = (RemoveMemberListResponse)context.Execute(req); } } } catch (Exception e) { throw new Exception("Unsubscribe subscribers CRM (" + e.Message.ToString() + ")"); } }