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
srikanth11srikanth11 

how to convert aggregate field value to integer

hi all this is the query i used in the trigger and i want ot convert the lstar aggregate value in to integer value plz help how to do that

 

 

lstAR = [select Sum(Quantity_remaining__c)am from Inventory_Transaction__c where item__c=:ifl.item__c and warehouse__c=:ifl.warehouse__c  ]; 

 

 

hi i want the am value into a integer variable and also this is a trhgger so tell me the code part in view of a trigger

 

Best Answer chosen by Admin (Salesforce Developers) 
Navatar_DbSupNavatar_DbSup

You have to change the interger to double if sum contains the large value.

 

Double intdata =(Double)lstAR[0].get('am');
system.debug( 'Integer value ' + intdata );

All Answers

Navatar_DbSupNavatar_DbSup

Hi,

        you can use below code to work around on Aggregate result data.

 

Integer intdata =(integer)lstAR[0].get('am');
system.debug( ''Integer  value ' +  intdata );

 Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

srikanth11srikanth11

hi navatar this is the error i am getting while saving the record

 

System.TypeException: Invalid conversion from runtime type Double to Integer: Trigger.createinventorytransaction: line 13, column 18

srikanth11srikanth11

this is the changed trigger after using ur code

 

trigger createinventorytransaction on Item_fulfillement__c (after insert)
 {
 public list<AggregateResult> lstAR = new list<AggregateResult>();

// public integer am;
 
 for(Item_fulfillement__c ifl:trigger.new)
 {
 Inventory_Transaction__c[] it=[select id,Name,Item__c,Qty__c ,Quantity_fulfilled__c,Quantity_remaining__c,Quantity_taken__c,Warehouse__c from Inventory_Transaction__c where item__c=:ifl.item__c and warehouse__c=:ifl.warehouse__c order by date__c asc ];
 
lstar = [select Sum(Quantity_remaining__c)am from Inventory_Transaction__c where item__c=:ifl.item__c and warehouse__c=:ifl.warehouse__c  ]; 

Integer intdata =(integer)lstAR[0].get('am');
system.debug( 'Integer  value ' +  intdata );





}




}

 

Navatar_DbSupNavatar_DbSup

You have to change the interger to double if sum contains the large value.

 

Double intdata =(Double)lstAR[0].get('am');
system.debug( 'Integer value ' + intdata );

This was selected as the best answer
srikanth11srikanth11

thats a great help navatar dp sup