I've been trying for a few days to get this to work and but I've run out of ideas. I'm stuck. I can't get this test class to work. I get the following error.
Trigger
trigger efs_Sales_OrderTrigger on SCMC__Sales_Order__c (after update, after insert)
{
if(trigger.isAfter && trigger.isInsert)
efs__.EgnyteSyncQueueTrigger.onAfterInsert();
else if(trigger.isAfter && trigger.isUpdate)
efs__.EgnyteSyncQueueTrigger.onAfterUpdate();
}
Test Class
@isTest
public class efs_Sales_OrderTest {
static testMethod void mytestmethod(){
Test.startTest();
String uniqueUserName = 'systemadmin' + DateTime.now().getTime() + '@testorg.com';
Profile p = [SELECT Id FROM Profile WHERE Name='ACI System Admin'];
User u = new User(Alias = 'standt', Email='[email protected]',
EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US',
LocaleSidKey='en_US', ProfileId = p.Id,
TimeZoneSidKey='America/Los_Angeles',
UserName=uniqueUserName);
SCMC__PO_Payment_Terms__c popt = new SCMC__PO_Payment_Terms__c();
popt.SCMC__Terms_Name__c = 'N180';
insert popt;
SCMC__PO_Payment_Terms__c pt = [SELECT Id FROM SCMC__PO_Payment_Terms__c WHERE SCMC__Terms_Name__c = 'N180' LIMIT 1];
Account acc = new Account();
acc.Name = 'ACME';
acc.SCMC__Active__c = true;
acc.SCMC__Customer__c = true;
acc.SCMC__Currency__c = c.Id;
acc.SCMC__Payment_Terms__c = pt.Id;
acc.SCMC__Corp_Line1__c = '374 Hamilton Road';
acc.SCMC__Corp_City__c = 'New Hamburg';
acc.SCMC__Corp_PostalCode__c = 'N3A 2K2';
insert acc;
Account a = [SELECT Id FROM Account WHERE Name = 'ACME' LIMIT 1];
RecordType rt = [SELECT Id, Name from RecordType where Name = 'Inventory' AND SObjectType = 'SCMC__Sales_Order__c'];
System.runAs(u) {
SCMC__Sales_Order__c app = new SCMC__Sales_Order__c();
app.SCMC__Customer_Account__c = a.Id;
app.SCMC__Customer_Purchase_Order__c = '12345678';
app.RecordTypeId = rt.Id;
insert app;
update app;
}
Test.stopTest();
}
}
Error
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, SCMC.SalesOrders: execution of BeforeInsert
caused by: System.NullPointerException: Attempt to de-reference a null object
Class.SCMC.SalesOrders.validations: line 251, column 1
Class.SCMC.SalesOrders.onBeforeInsert: line 44, column 1
Class.SCMC.fflib_SObjectDomain.handleBeforeInsert: line 144, column 1
Class.SCMC.fflib_SObjectDomain.triggerHandler: line 314, column 1
Class.SCMC.fflib_SObjectDomain.triggerHandler: line 270, column 1
Trigger.SCMC.SalesOrders: line 9, column 1: []
I'm at a loss at this point.
SCMC.SalesOrders.validations
class on line 251- most likely because the mock Sales Order you are creating is missing a field value.