0

My company is using custom objects for Pricelist, Pricelist Items, and Products.

I'm having this error trying to test my method to get a return of the Pricelist object as a List of Id.

Line: 11, Column: 5 - "Static method cannot be referenced from a non static context: List IPriceDecorator.getPriceList(Id, Set)"

global class IPriceDecorator {

    global static List<Pricelist__c> getPriceList(Id priceListId, Set<Id> setProdId) {
        System.debug(LoggingLevel.ERROR, '__ [cls IPriceDecorator - getPriceList] - Start...');
        //System.debug(LoggingLevel.ERROR, '__ [cls IPriceDecorator - getPriceList] - priceListId: ' + priceListId);
        //System.debug(LoggingLevel.ERROR, '__ [cls IPriceDecorator - getPriceList] - setProdId: ' + setProdId);

        List<Pricelist__c> priceList = [ SELECT Id 
                                        , Name
                                        , IsActive__c
                                        FROM Pricelist__c
                                        WHERE Id =: setProdId ];

        System.debug(LoggingLevel.ERROR, '__ [cls IPriceDecorator - getPriceList] - priceList: ' + priceList);

        return priceList.isEmpty() ? null : priceList;       

    }

}

I'm running this snippet in Execute Anonymous.

String Id_Field = 'Id'; Id priceListId = 'a1t0O000005OsARQA0';
List<Product__c> prodList = [SELECT Id FROM Product__c];
System.debug('prodList: ' + prodList);

Set<Id> setProdId = new Set<Id>(); setProdId =
CollectionUtils.createSet(prodList, Id_Field);

System.debug('setProdId: ' + setProdId); IPriceDecorator obj = new
IPriceDecorator(); obj.getPriceList(priceListId, setProdId);

I really don't understand why this error occurs.

1 Answer 1

2

The getPriceList method is static. It is associated with the class IPriceDecorator, not an instance of the class.

You should call it like this:

IPriceDecorator.getPriceList(priceListId, setProdId)

You can read more about static methods in Apex here: Static and Instance Methods, Variables, and Initialization Code

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .