You need to sign in to do that
Don't have an account?
Tommy Georgiou
error on test class
Hello all,
I have these two trigger
and
for these triggers created the following test class
It fails to cover the triggers. The error on the test history is :
System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Account Name:You must enter a value: []
Any ideas why?
I have these two trigger
trigger InsertPriceBookTrigger on Order (before insert) { List<Pricebook2> stdPBL = [select id from Pricebook2 where IsStandard = TRUE]; if(!stdPBL.isEmpty()){ for(Order o: Trigger.new) o.PriceBook2Id = stdPBL[0].id; } }
and
trigger TaskTrigger on Task (after insert) { List<Order> ordersToUpdate = new List<Order>(); for(Task t : Trigger.new) { if(t.WhatId.getSObjectType() == Order.sObjectType && t.Subject.startsWith('Email:')) { ordersToUpdate.add(new Order(Id = t.WhatId, Status = 'Sent')); } } update ordersToUpdate; }
for these triggers created the following test class
@isTest public class Test3{ public static testmethod void InsertPriceBookTrigger_Test1() { Account a = new Account( Name = 'Test' ); insert a; Order o = new Order(name='Test1',EffectiveDate=system.today(),status='draft'); insert o; List<Pricebook2> stdPBL = [select id from Pricebook2 where IsStandard = TRUE]; if (!stdPBL.isEmpty()) { system.assertequals(stdPBL[0].id,o.PriceBook2Id); } } public static testmethod void TaskTrigger_Test1() { Order o = new Order(name='Test1',EffectiveDate=system.today(),status='draft'); insert o; Task t = new Task(whatid=o.id,Priority = 'normal',status='open',subject='Email:xxxx'); insert t; system.assertequals('Sent',o.status); } }
It fails to cover the triggers. The error on the test history is :
System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Account Name:You must enter a value: []
Any ideas why?
In your test class, before inserting any test records, please cross check the Mandatory fields in that object. Then provide the values for those mandatory fields in the test record. This will help you to avoid this issue.
Regards
TN Syed Moosa Nazir TN
But I have the account name inserted as the error defines.
As i see you are using standard order object and in Order Account is mandatory field and the error is coming while you are insering the order. Please check this and let me know if still there is any issue
Choose this as Best Answer if it helps you to solve the issue.
If this is what you were looking for then please mark it as a "SOLUTION" or You can Click on the "Like" Button if this was beneficial for you.
The problem is that I need to insert at least 1 product. I forgot to insert an account on the 2nd test class that is why it was failing. Now it's failing because I need at least 1 product in it
caused by: System.DmlException: Update failed. First exception on row 0 with id 801110000011RMSAA2; first error: FAILED_ACTIVATION, An order must have at least one product.: []
Trigger.TaskTrigger: line 11, column 1: []
Error: Compile Error: Invalid type: OrderLineItem at line 33 column 14