You need to sign in to do that
Don't have an account?
The Admiral
Test on calculation trigger errors..
Hi there,
Writing my second Test to check calculation I did with my trigger.
Quite new to writing apex tests so I took part of the test from first one and added here in but now I am lost.
20:34:26:101 EXCEPTION_THROWN [22]|System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Order__c, Investment__c]: [Order__c, Investment__c]
Writing my second Test to check calculation I did with my trigger.
Quite new to writing apex tests so I took part of the test from first one and added here in but now I am lost.
20:34:26:101 EXCEPTION_THROWN [22]|System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Order__c, Investment__c]: [Order__c, Investment__c]
@isTest private class TestCurrentInvestmentValue { @IsTest static void CurrentOrEndvalueCalculated() { // Create Investment_rates__c Investment_rates__c ir = new Investment_rates__c(FundPrice__c=100, Participation_unit__c=50); Test.startTest(); // Insert insert ir; Test.stopTest(); // Select the record to get the data modified after the trigger ir = [SELECT CurrentorEndvalue__c, FundPrice__c, Participation_unit__c FROM Investment_rates__c WHERE Id =: ir.Id]; // Check the values are as you espect System.assertEquals(ir.FundPrice__c*ir.Participation_unit__c, ir.CurrentorEndvalue__c); } Account account = new Account (Name='Test'); insert account; Investment__c invest = new Investment__c (Account__c=account.Id); insert invest; Contract contract = new Contract (AccountId=account.Id, Status='Draft', StartDate=System.today() + 30, ContractTerm=30); insert contract; Order order = new Order (AccountId=account.Id, Status='Draft', ContractId=contract.Id, EffectiveDate=System.today() + 60 ); insert order; Investment_rates__c investrates = new Investment_rates__c (DailyFundRecord__c=dailyfund.Id, Investment__c=invest.id, Order__c=order.id, FundPrice__c=400, Status__c='Open', Contract__c=contract.id); insert investrates; @IsTest static void CurrentOrEndvalueNotCalculated() { Investment_rates__c ir = new Investment_rates__c(); Test.startTest(); insert ir; Test.stopTest(); ir = [SELECT CurrentorEndvalue__c, FundPrice__c, Participation_unit__c FROM Investment_rates__c WHERE Id =: ir.Id]; System.assertEquals(0, ir.CurrentorEndvalue__c); } }
it turns out i had twice wrong account insert which i didnt see.
Went over it and solve it, :
All Answers
Make sure, you provide appropriate value for [Order__c, Investment__c]: [Order__c, Investment__c] while inserting records.
For further suggestions, you can check the below,
https://salesforce.stackexchange.com/questions/32769/system-dmlexception-insert-failed-first-exception-on-row-0-first-error-requi
If it helps you and close your query by marking it as the Best answer so that it can help others in the future.
Thanks.
it turns out i had twice wrong account insert which i didnt see.
Went over it and solve it, :