When I try to delete an OrderItem from an Order, I am getting a DML Mixed Exception. However, I am not updating any other object.
Am I missing something?
@istest
private class TestDeleteOrderItemEntry {
@future
static void del(Id oli) {
database.delete(oli);
system.assertEquals(0, [SELECT Id FROM OrderItem].size());
}
static testMethod void testDelete(){
Test.startTest();
Account a = new Account(Name='TestAccount');
insert a;
Contract c = new Contract(AccountId=a.Id, Name='TestContract',StartDate=system.today().toStartOfMonth(),ContractTerm=30,Status='Draft');
insert c;
c.Status = 'Activated';
update c;
Pricebook2 pb = new Pricebook2(Name='TestPriceBook');
insert pb;
Product2 prod = new Product2(Name = 'TestProduct');
insert prod;
Order o = new Order(AccountId=a.Id,ContractId=c.Id,EndDate=system.now().addDays(1).date());
o.EffectiveDate = system.today();
o.Status = 'Draft';
o.Pricebook2Id = pb.Id;
o.EndDate = system.today();
insert o;
PricebookEntry standardPrice = new PricebookEntry(
Pricebook2Id = Test.getStandardPricebookId(), Product2Id = prod.Id,
UnitPrice = 10000, IsActive = true);
insert standardPrice;
PricebookEntry priceEntry = new PricebookEntry(
Pricebook2Id = pb.Id, Product2Id = prod.Id,
UnitPrice = 10000, IsActive = true, UseStandardPrice=true);
insert priceEntry;
OrderItem item = new OrderItem(OrderId=o.Id, Quantity=1, UnitPrice=3, PriceBookEntryId=priceEntry.Id);
insert item;
del(item.Id);
Test.stopTest();
}
}
Error:
15:10:59:712 FATAL_ERROR System.DmlException: Delete failed. First exception on row 0 with id 8027A0000008qQYQAY;
first error: MIXED_DML_OPERATION, DML operation on setup object is not permitted
after you have updated a non-setup object (or vice versa):
CustomFieldDefinition, original object: OrderItem: []
Thanks,