You need to sign in to do that
Don't have an account?
Trigger Delete help
Hi,
Hello,
I have this Trigger that update the checkbox to true if an Opp has an attachment. and update the checkbox to false if I delete the attachment. This Trigger work fine.
But if Opp has 3 attachment and if I delete the one attachment it update the checkbox to false. How should I modify this trigger so it should update the checkbox to false only if there is no attachment
trigger Att_Aft_Trig on Attachment (after insert, after update,after delete)
{
if(trigger.isInsert || trigger.isUpdate){
List<Opportunity> co = [select id, Attachement__c from Opportunity where id =: Trigger.New[0].ParentId];
if(co.size()>0)
{
co[0].Attachement__c = true;
update co;
}
}
if(trigger.isDelete){
List<Opportunity> co1 = [select id, Attachement__c from Opportunity where id =: Trigger.old[0].ParentId];
if(co1.size()>0)
{
co1[0].Attachement__c = false;
update co1;
}
}
}
I would probably do something like this:
Best,
Adam