I created a custom field in my price book, Tier_1_Limit__c, which is a Number(10,0) field. I'm working with an extension to the Quote's standard controller and I simply want to compare the quantity value of a quote line item to the custom Tier 1 limit number field. The Pricebook Entry field definition, Apex code, and corresponding compile error are shown below.

Field Definition

enter image description here

Relevant Apex Code

        QuoteLineItem[] items = [
            from QuoteLineItem 
            where quote.id = :quote.id order by Product2.name, ListPrice, Quantity];

        for(QuoteLineItem item : items){

            if (item.quantity <= PricebookEntry.Tier_1_Limit__c) {
                // do something here

Error Message

Compile Error: Comparison arguments must be compatible types: Decimal, Schema.SObjectField

What am I doing wrong here? Please help if you can, thanks in advance.


You're treating PricebookEntry as a variable, but since it's a standard object name, it's a reserved string. Change your code to this:

for(QuoteLineItem item : items){

    if (item.quantity <= item.PricebookEntry.Tier_1_Limit__c) {
        // do something here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.