3

I am writing a trigger to handle after insert,after update and after delete events. I am using trigger.old for after delete.But, how to differentiate the deleted record from the rest of the records of the object?

What I have done so far is :

List<Object__c) lstTriggerOld = trigger.old;
List<Object__c> lstAllRecords = [SELECT Id FROM Object__c WHERE ID != NULL];
List<Object__c> deletedRecords = [SELECT Id FROM Object__c WHERE ID IN :lstTriggerOld AND ID NOT IN : lstAllRecords ];

But the last list is not fetching any rows.

Can someone help?

1 Answer 1

4

To get or Query deleted records you need to use ALL ROWS So your query will be

List<Object__c> deletedRecords = [SELECT Id FROM Object__c WHERE ID IN :lstTriggerOld AND ID NOT IN : lstAllRecords ALL ROWS];

All Rows Keyword

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .