Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unit testing 在Salesforce中编写触发器上的测试类_Unit Testing_Triggers_Salesforce - Fatal编程技术网

Unit testing 在Salesforce中编写触发器上的测试类

Unit testing 在Salesforce中编写触发器上的测试类,unit-testing,triggers,salesforce,Unit Testing,Triggers,Salesforce,我是一个完全不懂代码的人,需要帮助为Salesforce中的触发器编写测试类。任何帮助都将不胜感激 触发因素如下: trigger UpdateWonAccounts on Opportunity(before Update) { Set < Id > accountIds = new Set < Id > (); //Collect End user Ids which has won Opportunities for (Opportunity o :

我是一个完全不懂代码的人,需要帮助为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;
  }
}
trigger UpdateNoccounts on Opportunity(更新前){
SetaccountIds=newset();
//收集赢得销售机会的最终用户ID
for(机会o:触发器。新){
如果(o.isWon&&o.EndUserAccountName\uu c!=null){
accountIds.add(o.EndUserAccountName\uu\c);
}
}
列表lstcount=新列表();
//迭代并收集所有最终用户记录
对于(帐户a:[从Id所在的帐户中选择Id、状态\uu c:帐户Id]){
lstcount.add(新帐户(Id=a.Id,Status_uc=true));
}
//如果有任何帐户,则更新记录
如果(!lstcount.isEmpty()){
更新帐户;
}
}
阅读并确认

基本上,您希望创建一个新的testmethod来更新(插入、删除、取消删除等,具体取决于您的触发条件)记录或sObject

看起来有点像这样:

public class myClass {
    static testMethod void myTest() {
       // Add test method logic to insert and update a new Opportunity here
    }
}

您是否需要帮助来编写测试此特定触发器的代码?或者你只是需要帮助来创建一个单元测试类?