4

I am writing a test class for a trigger. But i am not able to run it properly it only contain 68%. The error is

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;/* */
   }
}

thanks Anuraj

Cem
  • 33
  • 6
Anu
  • 194
  • 1
  • 2
  • 11

1 Answers1

11

There is a validation rule on the Part object. To view the validation rule(s), go to Setup > Create > Objects > Part > Validation Rules.

You'll need to modify your code to create a Part__c record that complies with the validation rules.

Jeremy Ross
  • 11,544
  • 3
  • 36
  • 36
  • their is a condition castable__c = "No" I changed my code castable__c = 'yes' but i am getting this error Field is not writeable: Part__c.castable__c – Anu Dec 06 '11 at 18:18
  • Is castable__c a formula field? – Jeremy Ross Dec 06 '11 at 20:07
  • 1
    OK, well you can't write a value to a formula field. You have to look at the formula, then figure out which other field value(s) to set in order to have castable__c = "yes" – Jeremy Ross Dec 07 '11 at 16:38