+ Start a Discussion
Madhura BMadhura B 

String to Integer in SOQL

Hi,

 

I have a text field which holds numeric values like 1, 2, 3, 12,13 etc. Visualforce page displays these values as

1

12

13

2

3

 

how can I sort them as 1,2,3,12, 13.... Guess I can't use lpad in soql.

 

SFDCpassionSFDCpassion

Try using list's sort method 

PremanathPremanath

Take one list for that oupt values

List<Integer> varlist=New List<Integer>();

use for loop

then convert one by one into Integer

x=Integer.valueof(-------);

varlist.add(x);

 

sort the list like

 

varlist.sort();

 

 

Prem

Madhura BMadhura B

I don't think I can do that.

 

The code is as follows

List<Format_Conversion_Table__c> formatList=new List<Format_Conversion_Table__c>();

for(Format_Conversion_Table__c f:[Select Sublevels__c,Master_Column__c, KS5_Points__c, KS5_Grades__c, KS4_Points__c, KS4_Grades__c,KS3_Points__c, Id, BTECLevel3__c, BTECLevel2__c, BTECLevel1__c From Format_Conversion_Table__c Order By Master_Column__c ASC ])
{
formatList.add(f);
}

 Format list is then displayed on VF.

PremanathPremanath

Which field values you want to sort??

Madhura BMadhura B

Master_Column__c which is a text field holding numbers

PremanathPremanath

Hi follow this code

 

List<String> formatList=new List<String>();

List<Integer> realform=new List<Integer>();

for(Format_Conversion_Table__c f:[Select Sublevels__c,Master_Column__c, KS5_Points__c, KS5_Grades__c, KS4_Points__c, KS4_Grades__c,KS3_Points__c, Id, BTECLevel3__c, BTECLevel2__c, BTECLevel1__c From Format_Conversion_Table__c Order By Master_Column__c ASC ])
{
formatList.add(f.Master_Column__c);
}

 

for(String s:formatList){

   realform.add(Integer.valueOf(s));

}

 

realform.sort();

System.Debug(realform);

Rahul SharmaRahul Sharma

Using two for loops is not even required over here. In first loop itself you could collect the type-casted list of Integers and sort them.