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
Christos KolonisChristos Kolonis 

Trigger is not deleting the records which i have to delete

Hello, 

I need a trigger which will run when the Opportunity is in stage "X". I have a handler apex class which checks if the Opportunity is in this stage and if it is, gets the Opportunity's attachments and deletes them. This Stage is updated by another apex class and trigger from another custom object. So, if i select manually the stage it functions as it should but if the stage is updated by the apex, my new trigger is not running. I am using before insert trigger. Any thoughts??

Thank you!
ShirishaShirisha (Salesforce Developers) 
Hi Christos,

Greetings!

I don't think before insert works to delete the child record(since an attachments considered as Child record for the Object).I would suggested you to go with the Before Update trigger as suggested in the below thread.

https://salesforce.stackexchange.com/questions/45566/deleting-child-records-on-a-parent

Kindly mark it as best answer if it helps so that it can help others in the future.

Warm Regards,
Shirisha Pathuri
Christos KolonisChristos Kolonis
Hello Shirisha,

My fault, my trigger is before update. Miss spelling!