Deleted records still showing in search

I have an `after_delete` logic hook for `Accounts` such that it delete all associated `Notes` and `Contacts`. Here is the hook:

class DeleteAssociatedRecords {

function delete_associated_records( $bean, $event, $arguments ) {

$accountId = $bean->id;
// Delete related contacts. Notes cannot be queried this way for reasons unknown.
if ($bean->load_relationship('contacts')) {
//Fetch related beans
$relatedBeans = $bean->contacts->getBeans();

foreach( $relatedBeans as $index=>$relation ) {
$relation->mark_deleted($relation->id);
$relation->save();
}
}

// And now, delete related notes.
$bean = BeanFactory::getBean('Notes');

$sql = new SugarQuery();
$sql->from($bean);
$sql->Where()->equals('parent_id', $accountId)->equals('parent_type', 'Accounts');

$result = $sql->execute();

foreach( $result as $index=>$relation ) {
$noteId = $relation['id'];
$noteBean = BeanFactory::getBean('Notes', $noteId);
$noteBean->mark_deleted($noteId);
$noteBean->save();

}

The hook deletes the associated records as expected, but we're noticing that the deleted Contacts and Notes still show up in global search results, while the deleted Accounts are not returned.


Is there some extra step I'm missing to make sure deleted Notes and Contacts are not returned by global search?

Parents Reply Children
No Data