function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
svdsvd 

how to invoke apex method in soql query.[Convert string object to Integer]

Hi everyone,

I want to convert String into Integer so that I can filter data in my where clause of SOQL query.
I created a AutoNumber field on account object. In my SOQL query I want to get account objects 100 at a time into a list. So i did the following query.

Here is my query

// acc is a Account object

acc = [Select id from account a where ( a.AutoNum__c >= 1 and a.AutoNum__c < 100 )];

The problem is AutoNumber in salesforce is of type String. So I cant compare that field to integers 1 and 100. How can I achieve this.

Any example or syntax would help me. I know that valueOf can be used to convert string to integer, but how can i embed that into my SOQL query.

Thank you in advance.

its,
dsv
SuzanyuSuzanyu
Hi dsv,
 
I did some test on your issue. Below showing you my result that may be helpful.
 

Select c.Contact__c, c.Course_Date__c, c.Course_Name__c, c.Id, c.Name from Course__c c where c.Name> '0003'

you have to treat Auto Number as a String in where clause regardless the display of the field. By that I mean  for both display formats of A-{0000} and {0000} the query can work very well as above.
 
 
 
 
Sue
svdsvd
Hey,
I would like to know if I can use any apex functions inside the soql query.
eg: where Integer.valueOf(autoNum__c) > 1 and Integer.valueOf(autoNum__c)<100.

my query gets looped. so in next loop cycle I need autoNum__c>101 and < 200. and it goes that way.

I tried to achieve this using ...for( Acc a: [select id from acc]){// code}...but I ended up using more API calls..so I thought of taking 100 at a time in a list and update the entire list once. (Update ListObject.)

thanks,
dsv
Suman GiriSuman Giri

Any solution to the above scenario ???

 

We have a similar requirement, appreciate if any pointers provided.

 

Thanks in Advance