4

我正在为触发器编写一个测试类。但我无法正确运行它,它只包含 68%。错误是

System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, This part is not forecastable. 

@isTest
private class TestTriggers
{
   static testMethod void testService()
   {        
   //Insert part    
    list<Opportunity> Opportunity = new list<Opportunity>();
    Opportunity = [Select id from Opportunity];
    list<Product2> Product = new list<Product2>();
    Product = [Select id from Product2];
    Part__c p = new Part__c(Stage__c = 'idea',Product__c=Product[0].id,Opportunity__c=Opportunity[0].id);
    insert p;

   //Update part
    list<part__c> partlist = new list<part__c>();
    partlist =  [Select Stage__c from part__c where Stage__c = 'idea'];
    partlist[0].Stage__c = 'update';
    update partlist;/* */
   }
}

谢谢阿努拉

4

1 回答 1

11

Part 对象有一个验证规则。要查看验证规则,请转至设置 > 创建 > 对象 > 部件 > 验证规则。

您需要修改代码以创建符合验证规则的 Part__c 记录。

于 2011-12-06T17:10:03.933 回答