<p>


///Note: Salesforce has built in validation rule to prevent  deletion Accounts with related Contacts/ Opportunities.<br>
///Another option is to use Record triggered flow<br><br>
        trigger preventAccountDeletion on Account (before delete) {<br>
            &nbsp;&nbsp;// Check if the trigger is before delete<br>
            &nbsp;&nbsp;if (Trigger.isBefore && Trigger.isDelete) {<br>
                &nbsp;&nbsp;&nbsp;&nbsp;// Query for account IDs that have related contacts<br>
                &nbsp;&nbsp;&nbsp;&nbsp;List&lt;AggregateResult&gt; accountWithContact = [<br>
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SELECT AccountId<br>
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FROM Contact<br>
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;WHERE AccountId IN :Trigger.oldMap.keySet()<br>
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GROUP BY AccountId<br>
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HAVING COUNT(Id) > 0<br>
                &nbsp;&nbsp;&nbsp;&nbsp;];<br>
                &nbsp;&nbsp;&nbsp;&nbsp;// Throw an error if there are accounts with related contacts<br>
                &nbsp;&nbsp;&nbsp;&nbsp;if (accountWithContact.size() > 0) {<br>
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Trigger.old[0].addError(accountWithContact.size() + ' Accounts cannot be deleted because they have related contacts.');<br>
                &nbsp;&nbsp;&nbsp;&nbsp;}<br>
            &nbsp;&nbsp;}<br>
        }<br>
    </p>