You need to sign in to do that
Don't have an account?
Laetitia Damen 9
Test Query Class !
I'm looking to create a class test for my query order. It didn't work well.
I've missed something there for sure but I'm pretty new in testing.
Thanks in advance for your help!
Here is the class then the test class :
I've missed something there for sure but I'm pretty new in testing.
Thanks in advance for your help!
Here is the class then the test class :
public with sharing class FA_QR_Order { public FA_QR_Order() { } public AggregateResult getSum () { AggregateResult sum = [ SELECT SUM(TotalAmount) total FROM Order]; return sum; } public list<Order> getOrders() { list<Order> listOrders = [ SELECT Id, TotalAmount, AccountId, Status FROM Order ]; return listOrders; } }
@isTest public with sharing class TestQueryOrder { @isTest static void TestQueryOrder(){ Order orderTest = new Order(); orderTest.Status='Ordered'; orderTest.Name = 'NameTest'; orderTest.EffectiveDate = System.today(); orderTest.ShipmentCost__c= 56789; insert orderTest; list<Order> listOrdersTest = new list<Order>(); listOrdersTest.add(orderTest); Test.startTest(); FA_QR_Order OrderQr = NEW FA_QR_Order(); listOrdersTest = OrderQr.getOrders(orderTest); Order orderTest2= [ SELECT Id, TotalAmount, AccountId, Status FROM Order]; Test.stopTest(); System.assertEquals ( listOrdersTest.get(orderTest2)); } }
Please try the below test class:
Thanks,
Maharajan.C
But the test failed, here is the result :
caused by: System.NullPointerException: Attempt to de-reference a null object
Trigger.FA_TRH_UpdateAccountCA: line 26, column 1: []
Class.TestQueryOrder.TestQueryOrder: line 18, column 1
15:58:52.320 ended SFDX: Run Apex Tests
Can you please check the FA_TRH_UpdateAccountCA apex trigger... LIne No: 26... This line referring is some data from Account or Order... But that data is missing in our class test class... I think it's referring some account data... So please check the code once and update the test data or post your trigger here...
Simply you have to give the Account or order data properly (some field values are missing while inserting the order... The field could be from account or order) in our test class...
Thanks,
Maharajan.C