You need to sign in to do that
Don't have an account?
Rohith Kumar 98
Test class on trigger handler fail, why?
There is a custom object named Payment Order with Account as the lookup field.
I created a trigger on this custom object so that when creating a new record and choosing any Account as lookup then the values from the Account are populated in some fields of the Payment Order custom object.
For the above trigger, I created a Test Class:
but the actual value in System.assertEquals is null however expected value is the name of the account which is correct.
I tried the same code in execute anoynamous window, the created Account name and Payment Order's payee name is the same and not null like in the test method.
Trigger working fine, then why I am getting null value in the test class in System.assertEquals(newAccount.Name, paymentOrder.Payee_Name__c); for the highlited parameter.
I created a trigger on this custom object so that when creating a new record and choosing any Account as lookup then the values from the Account are populated in some fields of the Payment Order custom object.
For the above trigger, I created a Test Class:
@isTest public class TestPaymentOrderTriggerHandler { @isTest static void TestUpdatePaymentContactInformationCheck(){ //Creating and Inserting new Account Account newAccount = new Account(Name = 'Test Account', Phone = '1234567890', BillingStreet = 'Test Billing Street', ShippingStreet = 'Test Shipping Street', ShippingPostalCode = '625014', ShippingState = 'Test State', ShippingCountry = 'Test country'); insert newAccount; //Creating and Inserting new Payment Order with created account as lookup Payment_Order__c paymentOrder = new Payment_Order__c(Account__c = newAccount.Id); insert paymentOrder; Test.startTest(); System.assertEquals(newAccount.Name, paymentOrder.Payee_Name__c); Test.stopTest(); } }
but the actual value in System.assertEquals is null however expected value is the name of the account which is correct.
I tried the same code in execute anoynamous window, the created Account name and Payment Order's payee name is the same and not null like in the test method.
Trigger working fine, then why I am getting null value in the test class in System.assertEquals(newAccount.Name, paymentOrder.Payee_Name__c); for the highlited parameter.
You need to query the paymentOrder to check the Payee_Name__c in Assert.
Thanks,
Maharajan.C