Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Salesforce by (11.9k points)

The problem is that I need to compare two fields of different types in a SOQL query.

TextField is a Picklist (so really text) and IntField is a Number(2, 0). Changing the types of these fields is not possible.

I would like to write SOQL like:

SELECT Id FROM SomeObject__c

WHERE Cast(TextField as Integer) > IntField

Obviously Cast(TextField as Integer) does NOT work.

Any advice on type conversion within SOQL. The normal APEX functions (e.g. integer.valueof) don't seem to be of any help here.

Thanks

1 Answer

0 votes
by (32.1k points)
edited by

SOQL itself doesn't sustain casting but you can forever lend a helping hand ;)

Want to learn Salesforce from the scratch? Here's is the right video for you on Salesforce provided by Intellipaat!

You can go ahead and create a Numeric formula field in SomeObject__c:

IF(ISNUMBER(TextField__c), VALUE(TextField__c), NULL)

or something related depending on your definition of the cast to int. Now, you can go ahead and use this field in a SOQL query.

Be a certified Salesforce professional by going for Intellipaat’s Salesforce Certification!

Related questions

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

30.5k questions

32.5k answers

500 comments

108k users

Browse Categories

...