-2
set<decimal> volume = new set<decimal>();
    
for(QuoteLineItem record:newrecords){
   volume.add(record.Quantity);
}

[select From_Quantity__c where From_Quantity__c > :volume];

Can we use Greater than (>) operator for comparing set/list values?

It is not working, if we can't use it then what is an alternative way?

1 Answer 1

3

From_Quantity__c is a single-value field, so it is not possible to compare it to set of values. For example, you have From_Quantity__c = 1 and volume = {0, 2}. Is 1 > {0, 2}? It makes no sense.

You should compare only matching values. So, for example, get greatest record.Quantity for Decimal volume or get sum of quantities, as it suites for your business case. But you cannot compare a single-value field From_Quantity__c with set of values.

UPDATE with code sample for maxVolume:

Decimal maxVolume = 0.0;

for (QuoteLineItem record : newrecords) {
    if (record.Quantity > maxVolume) {
        maxVolume = record.Quantity;
    }
}

for (Mode__c record : [SELECT From_Quantity__c FROM Mode__c WHERE From_Quantity__c > :maxVolume]) {
    
}
4
  • can you provide some code , to compare the values for my use case Jul 23, 2021 at 8:18
  • How to get greatest of record.Quantity in apex, i have used MAX also it is not working Jul 23, 2021 at 8:45
  • @SalesforceEmail I have updated the answer, please, take a look. Jul 23, 2021 at 9:03
  • Great Answer , suddenly i am not able to strike it. Jul 23, 2021 at 9:27

You must log in to answer this question.

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