Deleting records in an after trigger

I have this trigger on a custom object

trigger mytrigger on Merchandise__c (after insert) {
merchandise__c m = [select name from merchandise__c where id[0].id]; = 'hi';
delete m;

As per this documentation,above should have given a run time error

Additionally, if you update or delete a record in its before trigger,
or delete a record in its after trigger, you will receive a runtime
error. This includes both direct and indirect operations. For example,
if you update account A, and the before update trigger of account A
inserts contact B, and the after insert trigger of contact B queries
for account A and updates it using the DML update statement or
database method, then you are indirectly updating account A in its
before trigger, and you will receive a runtime error

Here i am deleting the record in an after insert and when i try creating a record from standard UI and save it doesnt give me run time error but below message

Record deleted

The record you attempted to access has been deleted. The user who
deleted this record may be able to recover it from the Recycle Bin.
Deleted data is stored in the Recycle Bin for 15 days.

Can see record simply gets deleted ,no run time error
Now my query is ,documentation is not correct? or are they talking about a completely different thing?


You can’t delete the record in You can delete the record by ID, but you can’t delete the record by reference.




delete [select id from merchant__c where id in];

Source : Link , Question Author : sfdc99999 , Answer Author : sfdcfox

Leave a Comment