I am new in Apex Development. I want to write a TestClass for my Apex Trigger.
I am sharing my code with you:
trigger ClosedOpportunityTrigger on Opportunity (before update) {
for(Opportunity o:Trigger.New) {
if(o.Probability==100 && o.Invoiced__c == true)
{
Attachment a = new Attachment();
try {
a = [Select Id, Name from Attachment where ParentId =:o.Id];
}
catch(Exception e) {
a = null;
}
if (a == null)
o.addError('Add an attachment before you close the Opportunity');
}
}
}
Goodluck