2

I apologize for this rookie question.

I have a post update trigger which will create a new record if a certain field is checked on a record. It was running fine. However, now that I have added new validation rules the test code for it is no longer running properly. The validation checks the contents of the parent record of the current record. If a certain field is blank on the parent record the validation rule will prompt the user to change the parent record's value, and will therefore not proceed with the trigger.

I have added a line to the test code which will give a value to that parent record but the test code still errors out when it is run. Here is the test code :

@isTest
private class testProjectInitiationTrigger {

    static testMethod void ProjectInitiationTriggerTest() {

        Account account = TestHelper.createAccount();
        Opportunity objOpp = TestHelper.createOpp(account);

        //this is the parent record being created
        Country_by_Country__c objC = TestHelper.createCBC(objOpp);
        objC.Current_Tvl_Mgmt_Supplier__c = 'Test Supplier';

        //this is the child record which the trigger will run off
        Project_Initiation_del__c oPI = new Project_Initiation_del__c();
        oPI.Name =  objC.Name;
        oPI.Country_by_Country__c = objC.Id;
        oPI.BCD_Travel_Business_Owner__c = objC.CreatedById;
        oPI.CDS_Product_s_Sold__c = 'Product A';
        insert oPI;

        //this is the child record field which will initiate the post update trigger
        oPI.Initiate_Implementation__c = true;
        update oPI;
    }
}

The field which is in question is Current_Tvl_Mgmt_Supplier__c. I'm populating it with "Test Supplier" but the Validation Rule which checks to see if it is blank is still causing this test code to fail.

Does anybody know what I can do to satisfy the Validation Rule in this test code ?

Thank you very much for your help.

3

You changed the value in memory, but you didn't commit the change to the database, so the validation rule doesn't see it:

    //this is the parent record being created
    Country_by_Country__c objC = TestHelper.createCBC(objOpp);
    objC.Current_Tvl_Mgmt_Supplier__c = 'Test Supplier';
    update objC;  //  <<< ADD THIS LINE

Add the line commented above to commit the change.

  • 2
    You're welcome, @Zoom_v. If this helped you, please mark my answer as accepted (check mark icon). Thanks! – Jason Clark Aug 16 '13 at 14:25
  • 1
    fwiw - I had intended to do that. I was required to wait at least 5 min after your answer to mark it. I'm just coming back here now. :-) Thanks again. – Zoom_v Aug 16 '13 at 15:15

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.