You need to sign in to do that
Don't have an account?

Trigger (before delete)
trigger AccountDeletion on Account (before delete) { for (Account a : [SELECT Id FROM Account WHERE Id IN (SELECT AccountId FROM Opportunity) AND Id IN :Trigger.old]) { Trigger.oldMap.get(a.Id).addError( 'Cannot delete account with related opportunities.'); } }What is meaning of Trigger.oldMap.get(a.Id).addError() and why can't we use a.addError( ) as it is iterating only over the records which has opportunity.
Please Explain it will be a great help.
addError(errorMsg)Marks a record with a custom error message and prevents any DML operation from occurring.Signature
public Void addError(String errorMsg)
The error message to mark the record with.
When used on Trigger.new in before insert and before update triggers, and on Trigger.old in before delete triggers, the error message is displayed in the application interface.
If you doing SOQL means that record is not part of you DML operation. That record will come directly from Database.
Please let us know if this will help u