AnsweredAssumed Answered

how to cleanly ERASE a list from accounts and contacts from the database after importing

Question asked by Paul Carlton on Oct 23, 2015
I know there's a button, I'm saying this after you've imported for accounts and then uploaded the same list for contacts to associate themselves to accounts.  It's too late to press that button afterwards.  So currently this is what I am doing to erase records from accounts AND contacts AND emails too.  Think of it like inner for loops.

  1. Selecting accounts.id of "mkttype_c" equal to the list.  It's a custom field we created for delineating imports and list types so we know where a list is coming from.
  2. I am then selecting all the contacts with the accounts_contacts id inner join
  3. I then delete each email_addr_bean_rel id and email_addresses id foreach emails selected from contacts
  4. I am then deleting each contact and accounts_contacts related row
  5. I am then selecting all emails per account inner join email_addr_bean_rel.
  6. I am then selecting email_addr_bean_rel id and email_addresses id the account
  7. I am then deleting the emails from the accounts level with the related emails row
  8. I am then deleting each account
# pseudocode to illustrate
accounts = select('accounts', 'mkttype_c');  for account in accounts:    contacts = select('contacts, accounts_contacts', account['id'])    for contact in contacts:      emails = select('email_addresses, email_addr_bean_rel', contact['id'])      for email in emails:        delete(email['id'], email['rel_id'])      delete(contact['id'], contact['account_contact_id']    emails = select('email_addresses, email_addr_bean_rel', account['id'])    for email in emails:      delete(email['id'], email['rel_id'])    delete(account['id'])

Is this the correct way of deleting a list from the database?  Am I missing anything that should looked at?  Please be aware I'm talking about a new import that has not been worked on yet.

Thank you for you insight!  Any employees or professional staff on site, I welcome your scrutiny, this has to be nailed!  Thanks!

The reason why I am asking is because I've imported a list a twice now and I'm seeing shifting import numbers, and contacts are being duped out when they shouldn't !  This is weird behavior and makes me think it has to do with how I'm delete these out of the database.  Please advise!

Outcomes