I am trying to put together a test class for a Visualforce page controller, but I keep getting the error message. Does anyone know how I can fix?
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, OpportunityLineItemTrigger: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.OpportunityLineItemTrigger: line 3, column 1: [] Stack Trace Class.VF_opportunityProductEntryTests.theTests: line 55, column 1
TEST CLASS
@istest
private class VF_opportunityProductEntryTests {
static testMethod void theTests(){
Account acc = new Account(Name = 'Test');
insert acc;
Contact con = new Contact(
FirstName = 'Test',
LastName = 'Name',
AccountId = acc.Id,
Phone = '555-555-5555',
MailingStreet = 'TestStreet',
MailingCity = 'TestCity',
MailingState = 'TestState',
MailingPostalCode = '00000',
MailingCountry = 'MailingCountry',
email = '[email protected]'
);
insert con;
Opportunity opp = new Opportunity(
AccountId = acc.Id,
Contact__c = con.Id,
Billing_Contact__c = con.Id,
Name = 'Test Account - Opp',
Amount = 2000,
CloseDate = date.today(),
StageName = 'Order Pending',
Type = 'New',
);
insert opp;
Pricebook2 pb22 = new Pricebook2(Name='testPB');
insert pb22;
Product2 newProd = new Product2(Name = 'test product', ProductCode = 'aaaaa', isActive = true, family = 'test family');
insert newProd;
PriceBookEntry pbEntry = new PriceBookEntry(
UnitPrice = 300.00,
PriceBook2Id = Test.getStandardPricebookId(),
Product2Id = newProd.Id,
UseStandardPrice = false,
IsActive = true);
insert pbEntry;
OpportunityLineItem ol = new OpportunityLineItem(
pricebookentryid=pbEntry.Id,
TotalPrice = 2000,
Quantity = 1,
UnitPrice = 1000.00,
OpportunityID = opp.Id);
insert ol;
TRIGGER IN ERROR (TriggerActivationControl__c = Custom Setting)
trigger OpportunityLineItemTrigger on OpportunityLineItem (before insert, before update, after insert, after update) {
TriggerActivationControl__c activation = TriggerActivationControl__c.getValues('OpportunityLineItemTrigger');
Boolean isActive = activation.TriggerActive__c;
if(isActive){
new OpportunityLineItemTriggerHelper().process();
}
}
CLASS
public class OpportunityLineItemTriggerHelper extends TriggerHelper{
public override void processAfterInsert(){
Set<Id> productIdSet = new Set<Id>();
for(OpportunityLineItem productInstance : (List<OpportunityLineItem>)Trigger.new){
productIdSet.add(productInstance.Id);
}
ShutterstockProductMethods.processShutterstockPublicAPIInfo(productIdSet);
}
public override void processAfterUpdate(){
Set<Id> productIdSet = new Set<Id>();
for(OpportunityLineItem productInstance : (List<OpportunityLineItem>)Trigger.new){
OpportunityLineItem oldProductInstance = (OpportunityLineItem)Trigger.oldMap.get(productInstance.Id);
if(productInstance.Image_ID__c != oldProductInstance.Image_ID__c){
productIdSet.add(productInstance.Id);
}
}
if(productIdSet.size() > 0){
ShutterstockProductMethods.processShutterstockPublicAPIInfo(productIdSet);
}
}
}