0

我是一个完整的代码菜鸟,需要帮助为 Salesforce 中的触发器编写测试类。任何帮助将不胜感激。

这是触发器:

trigger UpdateWonAccounts on Opportunity(before Update) {
  Set < Id > accountIds = new Set < Id > ();

  //Collect End user Ids which has won Opportunities
  for (Opportunity o : Trigger.new) {
    if (o.isWon && o.EndUserAccountName__c != null) {
      accountIds.add(o.EndUserAccountName__c);
    }
  }

  List < Account > lstAccount = new List < Account > ();

  //Iterate and collect all the end user records
  for (Account a : [Select Id, Status__c From Account where Id IN : accountIds]) {
    lstAccount.add(new Account(Id = a.Id, Status__c = true));
  }

  //If there are any accounts then update the records
  if (!lstAccount.isEmpty()) {
    update lstAccount;
  }
}
4

1 回答 1

1

阅读Apex 代码测试方法简介如何编写触发器测试

基本上,您想创建一个新的测试方法来更新(插入、删除、取消删除等,具体取决于您的触发条件)记录或 sObject。

它看起来有点像这样:

public class myClass {
    static testMethod void myTest() {
       // Add test method logic to insert and update a new Opportunity here
    }
}
于 2012-10-03T21:29:32.637 回答