Problem
When deploying test classes after upgrading to CloudSense R36, test methods fail with the following validation error:
System.DmlException: Insert failed. First exception on row 0; first error:
FIELD_CUSTOM_VALIDATION_EXCEPTION, Price Item Role and Type combination null - null is not valid.
This error blocks deployment and test execution for any test classes that create Price Item (cspmb__Price_Item__c) records, preventing successful completion of the R36 upgrade testing.
Root Cause
The R36 CloudSense upgrade introduced mandatory validation rules on the Price Item object, requiring two fields to be populated together:
- cspmb__Role__c - Product hierarchy classification (Master/Variant/Basic/Offer)
- cspmb__Type__c - Product structure type (Commercial Product/Add-On/Related Product)
These fields became mandatory as part of the PPDM (Product and Pricing Data Model) upgrade in February 2024, where the cspmb__Role__c field was made "Not Null" because it is price-affecting.
If your test classes use a factory method (e.g., buildPriceItem() in a test utility class like CS_ProductTestFactory.cls) to create Price Item test data, and this factory method was not updated to include these mandatory fields, all test classes using this factory will fail.
Diagnosis Steps
- Review the Test Failure: Examine the test failure error message to identify:
- The test class name (e.g.,
CustomButtonSynchronizeWithOppTest) - The line number where the Price Item insert fails
-
The error message confirming "Role and Type combination null - null is not valid"
-
Locate the Factory Method: Search your codebase for the test utility class that creates Price Item records. Common patterns:
- Class name:
*TestFactory,*TestDataFactory,*TestUtils -
Method name:
buildPriceItem(),createPriceItem(),generatePriceItem() -
Check Factory Implementation: Open the factory class and verify if the method includes the mandatory fields:
apex public static cspmb__Price_Item__c buildPriceItem(...) { cspmb__Price_Item__c pi = new cspmb__Price_Item__c( Name = name, cspmb__One_Off_Charge__c = oc, cspmb__Recurring_Charge__c = rc, // Check if these fields are present: cspmb__Role__c = ?, cspmb__Type__c = ? ); return pi; } -
Count Affected Test Classes: Search for all references to the factory method to understand the impact:
In Developer Console: File > Open > Search for "buildPriceItem(" across all Apex classes
Resolution
Update the factory method to include the mandatory R36 fields with safe defaults:
Example Fix
Before (missing mandatory fields):
public static cspmb__Price_Item__c buildPriceItem(String name, Decimal oc, Decimal rc, String prodCode) {
cspmb__Price_Item__c pi = new cspmb__Price_Item__c(
Name = name,
cspmb__One_Off_Charge__c = oc,
cspmb__Recurring_Charge__c = rc,
cspmb__Product_Definition__c = prodId,
cspmb__Price_Item_Code__c = prodCode
);
insert pi;
return pi;
}
After (with mandatory fields):
public static cspmb__Price_Item__c buildPriceItem(String name, Decimal oc, Decimal rc, String prodCode) {
cspmb__Price_Item__c pi = new cspmb__Price_Item__c(
Name = name,
cspmb__One_Off_Charge__c = oc,
cspmb__Recurring_Charge__c = rc,
cspmb__Product_Definition__c = prodId,
cspmb__Price_Item_Code__c = prodCode,
cspmb__Role__c = 'Basic', // R36 mandatory field
cspmb__Type__c = 'Commercial Product' // R36 mandatory field
);
insert pi;
return pi;
}
Recommended Safe Defaults
- Role:
'Basic'- This is the most common role for standard price items and was used as the default value during the PPDM migration when 332 null Role records were mass-updated. - Type:
'Commercial Product'- This is the standard type for primary product offerings.
Alternative: Parameterize the Fields
If your test classes need to test different Role/Type combinations, update the factory method signature to accept these as parameters:
public static cspmb__Price_Item__c buildPriceItem(
String name,
Decimal oc,
Decimal rc,
String prodCode,
String role, // New parameter
String type // New parameter
) {
cspmb__Price_Item__c pi = new cspmb__Price_Item__c(
Name = name,
cspmb__One_Off_Charge__c = oc,
cspmb__Recurring_Charge__c = rc,
cspmb__Product_Definition__c = prodId,
cspmb__Price_Item_Code__c = prodCode,
cspmb__Role__c = role != null ? role : 'Basic',
cspmb__Type__c = type != null ? type : 'Commercial Product'
);
insert pi;
return pi;
}
Deployment Steps
- Update the factory method in your test utility class.
- Save the class.
- Re-run the affected test classes to verify they now pass.
- Deploy the updated test utility class to your target environment.
Prevention
- Review Factory Methods After Upgrades: After each major CloudSense upgrade, review all test factory methods to ensure they include any newly mandatory fields.
- Monitor Validation Rules: Check CloudSense release notes for new validation rules or mandatory fields introduced in the upgrade.
- Test Early: Run test classes in a sandbox environment immediately after upgrading to identify any test data issues before deploying to production.
Related Information
- Affected Object:
cspmb__Price_Item__c - Mandatory Fields:
cspmb__Role__c,cspmb__Type__c - Introduced In: R36 (PPDM upgrade, February 2024)
- Common Factory Class Names:
CS_ProductTestFactory,TestDataFactory,TestUtils - Error Type:
FIELD_CUSTOM_VALIDATION_EXCEPTION - Historical Context: During the PPDM migration, 332 null Role records were mass-updated to 'Basic'
Priyanka Bhotika
Comments