0

One of columns(id) in Salesforce custom object is String type though it always contains long type values. I want to run query something like this.

Where id >= '123' and id <= '123456';

Is there any solution for this? It's not possible to change data type of column in Salesforce.

Matt K
  • 7,207
  • 5
  • 39
  • 60
RandomQuestion
  • 6,778
  • 17
  • 61
  • 97

2 Answers2

3

data type conversion is not possible as part of the SOQL syntax. You would need bring back the full result set and filter the results. Or if you can't change the data type then maybe you can use formula field or workflow update to copy the field into a hidden field that you can perform a greater than less than query on. It isn't best practice but it's an idea if you are really stuck for a solution.

Ultimately, though the correct answer would to either pad the number with leading zeros if they need to be text based or change the data type to a number.

John De Santiago
  • 1,194
  • 7
  • 8
-1

if your id always contain long type values, then you can use the following where clause

WHERE CONVERT(BIGINT, id) BETWEEN 123 AND 123456

However it will raise an error if your ID is not a numeric value

Nick
  • 1,128
  • 7
  • 12
  • is this `Convert` function supported in SOQL? I am trying in Force.com explorer but seems its not working. – RandomQuestion May 17 '12 at 01:12
  • i am not sure about the SOQL, but you can refer to [this post](http://stackoverflow.com/questions/5915584/soql-type-conversion-salesforce-com) – Nick May 17 '12 at 01:27