Intellipaat 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

0 votes
2 answers
asked Jul 15, 2019 in Salesforce by Kartik12234 (11.9k points)
0 votes
2 answers
0 votes
1 answer
0 votes
1 answer

1.2k questions

2.7k answers

501 comments

693 users

Browse Categories

...