1

I'm getting an error for the Timecard object and needing to write a test code for a DLRS rollup. My parent object is the Milestones in PSA and I'm rolling up the total hours field from the Timecard header.

Error:

dlrs_pse_Timecard_HeaderTest.testTrigger System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Timecard Header must specify a Project.: [pse__Project__c] Class.dlrs.RollupService.testHandler: line 282, column 1 Class.dlrs_pse_Timecard_HeaderTest.testTrigger: line 11, column 1

I'm not a developer and would like to know what exactly I need to put in the Developer Console's Execute Anonymous Window. I believe I need to use the "TimecardProjectSelectorTest" apex class but not sure if that's correct or what else I need to format everything correctly in the window.

  • As dlrs is a managed package, you should not have any problems with failing unit tests. You can still migrate your rollup definitions, install the package, etc. – Adrian Larson Jan 31 at 15:58
  • @AdrianLarson This appears to be the autogenerated test class for a dynamically-deployed trigger from DLRS, which isn't part of the managed package. I presume the error is blocking the deployment of a child trigger, Christina? – David Reed Jan 31 at 16:00
  • Yes, I am aware. I have used the package quite a bit. :) I've never had the test classes present a problem despite extensive usage. – Adrian Larson Jan 31 at 16:01
  • Yes, the error is preventing the deployment of the child trigger. Others have said I need a Test Code but I don't know how to create one. – Christina Douglas Jan 31 at 17:21
  • The best resource for DLRS support is the community success group here – David Cheng Feb 1 at 7:06
3

The DLRS-autogenerated test classes look like this (I copied one of mine that is on OrderItem:

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

If you have some VR rule or Required Field config that requires a specific field to be present, you need to modify the line:

dlrs.RollupService.testHandler(new OrderItem()

to include more arguments like

dlrs.RollupService.testHandler(new OrderItem(Foo__c = 'val'));

The DLRS comment

// Force the dlrs_OrderItemTrigger to be invoked, fails the test if org config or other Apex code prevents this.

even says why the test may fail. In your use case, it appears some lookup object (pse__Project__c) is required on the insert of the detail object.

0

Thank you everyone for your willingness to assist me! Another consultant gave me a work around without having to mess with code. Instead of using the Timecard Header object, I used the Timecard split which allowed the child trigger to deploy for the rollup.

  • Please use comments to say thank you, apart from that your answer is fine as a it specifies how you have created a work around. – Dave Humm Jan 31 at 19:38

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.