function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
kmorf_entransformkmorf_entransform 

Trying to filter a query by values greater than and less than a certain value

 im trying to execute a query based on a certain range of numbers. for example we want to query Amount > 100 and < 500.

Im trying to execute this code but im getting an error saying;

EXCEPTION_THROWN|[110]|System.QueryException: Invalid bind expression type of String for column of type Decimal

 

Double grtValue = Double.valueOf(selectedAmountGrt);
 Double lessValue = Double.valueOf(selectedAmountLess);
            Select Amount from Opportunity where Avg_Annual_Volume__c >: grtValue OR Avg_Annual_Volume__c < : lessValue';

 

 

Best Answer chosen by Admin (Salesforce Developers) 
TheIntegratorTheIntegrator

Pradeep@cloud wrote:

Hello there!!

 

This error is probably in the query itself, Lets see, I think you don need to use the colon

Select Amount from Opportunity where Avg_Annual_Volume__c > grtValue OR Avg_Annual_Volume__c <  lessValue;

 

The above is your query, I have just removed :  Give it a try, Hope it helps!!


Hi Pradeep, that is incorrect, Apex script variables and expressions can be used in SOQL only if preceded by a colon, otherwise you get a syntax error.

All Answers

TheIntegratorTheIntegrator

The query looks fine to me, assuming  Avg_Annual_Volume__c is a number field with decimals. Could you put a system.debug before the query to print the 2 double values and see what they are getting.

Prady01Prady01

Hello there!!

 

This error is probably in the query itself, Lets see, I think you don need to use the colon

Select Amount from Opportunity where Avg_Annual_Volume__c > grtValue OR Avg_Annual_Volume__c <  lessValue;

 

The above is your query, I have just removed :  Give it a try, Hope it helps!!

TheIntegratorTheIntegrator

Pradeep@cloud wrote:

Hello there!!

 

This error is probably in the query itself, Lets see, I think you don need to use the colon

Select Amount from Opportunity where Avg_Annual_Volume__c > grtValue OR Avg_Annual_Volume__c <  lessValue;

 

The above is your query, I have just removed :  Give it a try, Hope it helps!!


Hi Pradeep, that is incorrect, Apex script variables and expressions can be used in SOQL only if preceded by a colon, otherwise you get a syntax error.

This was selected as the best answer