问题描述
问题是我需要在 SOQL 查询中比较两个不同类型的字段.
The problem is that I need to compare two fields of different types in a SOQL query.
TextField 是一个选择列表(所以真的是文本),而 IntField 是一个 Number(2, 0).无法更改这些字段的类型.
TextField is a Picklist (so really text) and IntField is a Number(2, 0). Changing the types of these fields is not possible.
我想写 SOQL 之类的;
I would like to write SOQL like;
SELECT Id FROM SomeObject__c
WHERE Cast(TextField as Integer) > IntField
显然 Cast(TextField as Integer)
不起作用.
关于 SOQL 中类型转换的任何建议.正常的 APEX 函数(例如 integer.valueof)在这里似乎没有任何帮助.
Any advise on type conversion within SOQL. The normal APEX functions (e.g. integer.valueof) don't seem to be of any help here.
谢谢
推荐答案
SOQL 本身不支持强制转换,但您可以随时伸出援助之手 ;)
SOQL itself does not support casting but you can always lend a helping hand ;)
在SomeObject__c
中创建一个数字公式字段:
Create a Numeric formula field in SomeObject__c
:
IF(ISNUMBER(TextField__c), VALUE(TextField__c), NULL)
或类似的东西,取决于您对强制转换为 int 的定义.现在您可以在 SOQL 查询中使用此字段.
or something similar depending on your definition of cast to int. Now you can use this field in a SOQL query.
这篇关于SOQL 类型转换 (SalesForce.com)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!