function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jan Kopejtko 2Jan Kopejtko 2 

Before delete trigger makes it unable to delete records

Hello, I've got a trigger, which causes that I am unable to delete records. This shows up:

There's a problem saving this record. You might not have permission to edit it, or it might have been deleted or archived. Contact your administrator for help.

 
trigger QuoteLineItemEmailBeforeDelete on QuoteLineItem (before delete) {
    Set<Id> quids = new Set<Id>();
    for(QuoteLineItem qli :Trigger.Old) {
        quids.add(qli.QuoteId);
    }
    Quote[] quo = [Select Id from Quote Where id In :quids];
  Messaging.reserveSingleEmailCapacity(trigger.size);
    List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();
    for (QuoteLineItem qli : Trigger.old) {
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
        email.setToAddresses(new String[] {'test@example.com'});
        email.setSubject('Oznámení o změně nabídky');
        email.setPlainTextBody('Došlo ke změně nabídky' + Quo[0].Name + '.<br>' + 'Pro otevření záznamu v Salesforce klikněte na následující odkaz:<br>' +  URL.getSalesforceBaseUrl().toExternalForm() + '/' + qli.Id);
        emails.add(email);
    }
    Messaging.sendEmail(emails);
}

 
Best Answer chosen by Jan Kopejtko 2
Christan G 4Christan G 4
Hi Jan, this sounds more like a permission issue rather than something have to do with your trigger. Do you see that error everytime you try to delete a QuoteLineItem record?

All Answers

Christan G 4Christan G 4
Hi Jan, this sounds more like a permission issue rather than something have to do with your trigger. Do you see that error everytime you try to delete a QuoteLineItem record?
This was selected as the best answer
Jan Kopejtko 2Jan Kopejtko 2
Christian, you were right. I had the email deliverability turned off. The email could not have been sent and thus I was not permitted to delete the record.