2

As part of the first step of the Apex Specialist Superbadge project, I am trying to insert mock data like this:

    //create test objects
    Product2 testEquipment1 = new Product2(Name='Test Equipment 1',
                                           Lifespan_Months__c=12);
    Product2 testEquipment2 = new Product2(Name='Test Equipment 2',
                                          Lifespan_Months__c=18);
    insert testEquipment1;
    insert testEquipment2;

    Case testCase = new Case(Status='New',
                              Subject='Test Maintenance Request');
    insert testCase;

    Work_Part__c testWorkPart1 = new Work_Part__c(Equipment__c=testEquipment1.Id,
                                                  Maintenance_Request__c=testCase.Id); 
    Work_Part__c testWorkPart2 = new Work_Part__c(Equipment__c=testEquipment2.Id,
                                                  Maintenance_Request__c=testCase.Id);

    insert testWorkPart1;
    insert testWorkPart2;

As part of the setup for the project I installed this unmanaged package in my Trailhead Playground, which included the Work Part custom object. Here is what the Work Part objects and fields section looks like in my developer org:

Work Part fields and relationships

I don't get any compiler errors, but I get the following error on insert testWorkPart1 when I try to run my test method: System.DmlException: Insert failed. First exception on row 0; first error: FIELD_FILTER_VALIDATION_EXCEPTION, No spare parts meet this description or name.: [Equipment__c]

Is anyone familiar with what this error message means? I wasn't able to find any posts where others were getting a similar message. It's strange to me that the term "spare parts" is used, I'm not sure what that means in a Salesforce context. Does this mean that Equipment__c isn't being recognized as a field on my Work Part object?

2 Answers 2

5

The error is because the Equipment__c (Lookup to Product) is having a lookup filter.

You have to find out the look up filter conditions specified on this field and make sure the product record you are linking to your Work Part record is meeting those conditions.

In your code, the testEquipment1 and testEquipment2 records are being set with only 2 fields Name and Lifespan_Months__c. once you find out the lookup filter requirements and assign those fields, it should resolve the error.

0

@vamsi-krishna is right. You need to add Replacement_Part__c =true for your Product2

    //create test objects
Product2 testEquipment1 = new Product2(Name='Test Equipment 1',
                                       Lifespan_Months__c=12,
                                     Replacement_Part__c =true);
Product2 testEquipment2 = new Product2(Name='Test Equipment 2',
                                      Lifespan_Months__c=18,
                                     Replacement_Part__c =true);

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .