You need to sign in to do that
Don't have an account?
ERROR: Static method cannot be referenced from a non static context
While performing validation on my Apex Trigger & helper class I run into the following error:
Static method cannot be referenced from a non static context: void OpportunityLineItemTriggerHandler.AutoScheduleLineItemsAfterUpdate(List<OpportunityLineItem>, Map<Id,OpportunityLineItem>)
Now in test sandbox ... I did not run into this error .. so I'm not sure why in production it fails ...
Trigger code:
Apex class code (first x lines ......)
Thanks in advance.
Static method cannot be referenced from a non static context: void OpportunityLineItemTriggerHandler.AutoScheduleLineItemsAfterUpdate(List<OpportunityLineItem>, Map<Id,OpportunityLineItem>)
Now in test sandbox ... I did not run into this error .. so I'm not sure why in production it fails ...
Trigger code:
OpportunityLineItemTriggerHandler updater = new OpportunityLineItemTriggerHandler();
Apex class code (first x lines ......)
Public void AutoScheduleLineItemsAfterInsert(List<OpportunityLineItem> NewOppLineItems) { System.debug('** * ** #20 AutoScheduleLineItemsAfterInsert'); //** Get prepped by retrieving the base information needed for generating schedule Date currentDate; Decimal NumberOfInstallments; //**Decimal numberPayments; Decimal paymentAmount; Decimal totalPaid; String ItemDescription; NumberOfInstallments = 1; //** Ensure default value for installments even when no value provided. //** Generate lists for bulkify on OpportunityItems etc. set<id> oppid = new set<id>(); List<Id> oppLineIdsList = new List<Id>(); List<OpportunityLineItemSchedule> newScheduleObjects = new List<OpportunityLineItemSchedule>(); //** Assign (new) added ID values to variables for (OpportunityLineItem ol : NewOppLineItems) { oppLineIdsList.add(ol.id); oppid.add(ol.opportunityid); } //** Create (parent) opportunity list so we have required into to retrieve account based product (pricebook) values. list<opportunity> opplist = [select id, AccountID,CurrencyIsoCode from opportunity where id in : oppid ]; for (opportunity opp: opplist) { //** So we have all we need. Account, Opportunity currency and ProductID system.debug('** * ** #44 AccountID: '+opp.AccountID); system.debug('** * ** #45 Opportunity Currency: '+opp.CurrencyIsoCode); //** For every OpportunityLineItem record, add its associated pricebook entry //** to a set so there are no duplicates. Set<Id> pbeIds = new Set<Id>(); //** PriceBookEntryID for (OpportunityLineItem oli : NewOppLineItems) //** pbeIds.add(oli.pricebookentryid); pbeIds.add(oli.id); //** For every OpportunityLineItem record, add its associated oppty //** to a set so there are no duplicates. Set<Id> opptyIds = new Set<Id>(); for (OpportunityLineItem oli : NewOppLineItems) opptyIds.add(oli.OpportunityId);
Thanks in advance.
All Answers
This error states that at some point in your code, you are trying to call a Static method from an instantiated object.
is Any method in your trigger handler static? If so, how are you invoking it?
Static methods in salesforce a little different (and in my opinion more useful) than static methods in other programming languages, but conditional invocation of static methods from an instantiated object might give this error you are getting.
good luck!
The handler has 'only' two methods.
Public static void AutoScheduleLineItemsAfterInsert(List<OpportunityLineItem> NewOppLineItems)
Public static void AutoScheduleLineItemsAfterUpdate(List<OpportunityLineItem> NewOppLineItems, Map<ID,OpportunityLineItem> OldOppLineItems)
Both are called from the trigger.
else if (Trigger.isAfter){
if(Trigger.isUpdate){
//Code to execute after update
OpportunityLineItemTriggerHandler updater = new OpportunityLineItemTriggerHandler();
updater.AutoScheduleLineItemsAfterUpdate(Trigger.new,Trigger.oldMap);
}
if(Trigger.isInsert){
//Code to execute after insert
OpportunityLineItemTriggerHandler.AutoScheduleLineItemsAfterInsert(Trigger.new);
}
you are calling the static method from an instantiated object :)