SOQL Type conversion (SalesForce.com)

拥有回忆 提交于 2019-12-01 15:07:52

问题


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 advise on type conversion within SOQL. The normal APEX functions (e.g. integer.valueof) don't seem to be of any help here.

Thanks


回答1:


SOQL itself does not support casting but you can always lend a helping hand ;)

Create a Numeric formula field in SomeObject__c:

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

or something similar depending on your definition of cast to int. Now you can use this field in a SOQL query.



来源:https://stackoverflow.com/questions/5915584/soql-type-conversion-salesforce-com

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!