You need to sign in to do that
Don't have an account?
PerGeert
Trigger which delete current object returns warning
I have a trigger on a custom object OpenInvoice__c:
trigger OpenInvoiceTrigger on OpenInvoice__c (after insert, after update) {
if (Trigger.isAfter) {
if (Trigger.isUpdate || Trigger.isInsert) {
// After insert and update, check if invoice balance is zero.
// If so, delete the record
List PaidInvoices= new OpenInvoice__c[0];
for (OpenInvoice__c i : Trigger.new) {
if(i.Balance__c == 0) {
PaidInvoices.add(new OpenInvoice__c(id = i.id));
}
}
delete PaidInvoices;
}
}
}
The idea being, when an OpenInvoice is created/updated and the balance is zero, simply delete the record. (This happens normally from an interface from an ERP system).
When I test this I get this warning/message:
Record deleted
The record you attempted to access has been deleted. The user who deleted this record can recover it from the Recycle Bin. Deleted data is stored in the Recycle Bin for 30 days.
The message probably is caused by the fact that the trigger is executing in another user context than the user entering the data. The record is deleted OK.
Any ideas on how to avoid this message and bring the user back e.g. to the object owning the OpenInvoice (the Account)?
could you instead block the creation of the record?
in the past i've also changed the record type on a record to lock or hide it from reports and dashboards.