我是 Apex 开发的新手。我想为我的 Apex 触发器编写一个 TestClass。
我正在与您分享我的代码:
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');
}
}
}