Custom deletion of contacts

Faye Spath asked on October 27, 2022 22:21

I need to know how to delete contacts that dont have subscriptions either individual or in groups. I am using a custom class in the cms that implements IDeleteContacts

    public int Delete(int days, int batchSize)
    {
        var whereCondition = GetWhere();
        ContactInfoProvider.DeleteContactInfos(whereCondition, batchSize);


        return ContactInfo.Provider.Get().Where(whereCondition).Count();
    }

    /// <summary>
    /// Selects all contacts that do not have a 'ContactStateID' (are from outside the US).
    /// </summary>
    public string GetWhere()
    {
        var condition = new WhereCondition();
        condition.And(new WhereCondition().WhereEmpty("EverbridgeContactId").Or().WhereEmpty("SendGridContactId"));
        return condition.ToString(true);
    }



    Will this return the contacts that are in groups also because I dont want to delete a contact that is in a group and that group is added to a newsletter subscription

            public string GetWhere()
    {
        var condition = new WhereCondition();
        condition.And(new WhereCondition().WhereEmpty("CompanyContactId").Or().WhereEmpty("SendGridContactId"));

        ObjectQuery<SubscriberInfo> subscriberQuery = _subscriberInfoProvider.Get().TopN(1).Column("SubscriberEmail");
        condition.Or().WhereNotExists(subscriberQuery);

        return condition.ToString(true);
    }

Recent Answers


Brenden Kehren answered on October 28, 2022 14:55

Faye,

I'd suggest checking out the API Examples for Email Marketing and Newsletter Recipient as well as the API Documentation for the ISubscriptionService interface.

What you'll end up doing is:

  1. Get ALL of your contacts (with valid email addresses and any other where parameters you wish),
  2. Get ALL of your email feeds,
  3. Loop through all your contacts,
  4. Inside that loop, check to see if the contact is subscribed to the newsletters in your list subscriptionService.IsSubscribed(subscriberID, newsletterID).
  5. If they are not, add them to a list for "deletion" or delete them at that time.

Give this a shot and see what you come up with.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.