Print this page

Convert aggregate results in string or integer

Knowledge Article Number 000181326
Description I am using a query and using max in it. How can I Convert aggregate results in string or integer
Resolution
You can use String.valueOf() and Integer.valueOf() to convert aggregate results in string or integer format.Below is the code snippet for the same :-

Code to convert
******************
public list<AggregateResult> countStudent = new list<AggregateResult>();
countStudent = [Select max(PATIENT_ID_NEW__c)am from Contact where createddate>=2013-06-03T12:54:40.000Z ];  
//double myInt = (double)countStudent[0].get('am');
String str = String.valueOf(countStudent[0].get('am')) ;
Integer I = Integer.valueOf(str) ;
//integer myInt= (integer)countStudent[0].get('am');
system.debug('+++'+str);
system.debug('+++'+I);




promote demote