0

I want to create a Declarative Rollup Summary , but I hit the following error :

dlrs_pse_AssignmentTest.testTrigger System.DmlException: Insert failed. First exception on row 0; first error: 

FIELD_CUSTOM_VALIDATION_EXCEPTION, Bill Rate is required: [pse__Bill_Rate__c] 
Class.dlrs.RollupService.testHandler: line 282, column 1 
Class.dlrs_pse_AssignmentTest.testTrigger: line 11, column 1

Scenarios is as follow :

  • Parent object : pse__Milestone__c

  • Child Object : pse__Assignment__c

  • Relationship field : pse__Milestone__c

  • Field to aggregate : Days_Active__c

  • Aggregate result field : Days_Active_Roll_Up__c

Manage child trigger :

/** * Auto Generated and Deployed by the Declarative Lookup Rollup Summaries Tool package (dlrs) **/ 
trigger dlrs_pse_AssignmentTrigger on pse__Assignment__c (before delete, before insert, before update, after delete, after insert, after undelete, after update) { 
dlrs.RollupService.triggerHandler(pse__Assignment__c.SObjectType); }   

 

/** * Auto Generated and Deployed by the Declarative Lookup Rollup Summaries Tool package (dlrs) **/ 
@IsTest private class dlrs_pse_AssignmentTest { @IsTest private static void testTrigger() { 
// Force the dlrs_pse_AssignmentTrigger to be invoked, fails the test if org config or other Apex code prevents this. 
   dlrs.RollupService.testHandler(new pse__Assignment__c()); } }

What might be the issue? I have deactivated the validation rule but still have this error.

1
  • Is Bill Rate is required: [pse__Bill_Rate__c] a required field in the schema for whatever object it is on? That is, this may not be a Validation Rule - it may be a Required= checkbox. Also, check all objects in the DLRS rollup chain for this field in case it is included on more than one object – cropredy Oct 30 '20 at 22:16
1

The field might be set to be required at the object level. You can modify the test created to include values for the pse__Assignment__c object that is inserted in the test.

To do this, you should build the rollup in a sandbox first. Then you can edit the dlrs_pse_AssignmentTest class and modify the line

dlrs.RollupService.testHandler(new pse__Assignment__c()); } }

to be something like

dlrs.RollupService.testHandler(new pse__Assignment__c(pse__Bill_Rate__c = 1)); } }

Once the test passes in the sandbox, then you can deploy using a change set or other tools.

See https://github.com/afawcett/declarative-lookup-rollup-summaries/wiki/Challenges-with-Code-Coverage for more information.

4
  • Daniel, thank you so much. I tried to complete the test class but I have the following error : * classes/dlrs_pse_AssignmentTest.cls (Line: 10: Column:32) : Type requires name=value pair construction: pse__Assignment__c* – Elena Nov 1 '20 at 18:24
  • I'd need to see the code you are using. Also, I'm making an assumption on the field type that it is a number. – Daniel Hoechst Nov 2 '20 at 2:38
  • I added bellow statement on the DRLS in my test class. Because I want to be applied for all the assignments with Bill rate higher than 0 . Bill rate is a currency field. dlrs.RollupService.testHandler(new pse__Assignment__c(pse__Bill_Rate__c > 0)); – Elena Nov 2 '20 at 12:18
  • You can't do that. You are just creating a sample pse__Assignment__c record for the tests to run on. It needs to be something like pse__Bill_Rate__c = 0 – Daniel Hoechst Nov 2 '20 at 23:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.