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
magandrezmagandrez 

Problem getting AgreggateResult from the list

Hi all,

 

I have a problem getting the value from an AgreggateResult returned by an SOQL. Here is the code from the SOQL:

 

        total = [SELECT SUM(Total_Net__c)tmp
                 FROM Selected_Product__c
                 WHERE Service_Reservation__c =:servOrder
                 GROUP BY Service_Reservation__c];
              system.debug('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%'+total);    

 That system.debug gives me this: 

 

16:17:01:123 USER_DEBUG [24]|DEBUG|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%(AggregateResult:{tmp=40.0})

 Which is the value I want to show. In a different method I try to return 'result' as integer this way:

 

    public integer result {get; set;}

...


 public integer getResult(){
    
       integer result;
       for(AggregateResult ar:total){
       
           result = (integer)ar.get('tmp');
       system.debug('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%'+result);
       }
                                     
       return result;
    }

NOTE: When I debug this it never gets to the system.debug, but salesforce allows me to save this code (hence, no syntax errors).

 

And in the VF page I call for result this way:

 

<apex:outputText value="{!result}"/>

 

And no result at all (empty).

 

Do you have any idea of why this is happening?. Any solution?

 

Many thanks,

 

MGA.

TheIntegratorTheIntegrator

change result to decimal

 

decimal result;
       for(AggregateResult ar:total){
       
           result = (decimal)ar.get('tmp');

 

magandrezmagandrez

Hi,

 

It didn't work. The same problem.

 

Any other guess?

TheIntegratorTheIntegrator

Could you share your debug log?

magandrezmagandrez

Sure. Here you

24.0 APEX_CODE,FINEST;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WORKFLOW,INFO
10:23:55.095 (95648000)|EXECUTION_STARTED
10:23:55.095 (95681000)|CODE_UNIT_STARTED|[EXTERNAL]|066R00000009cJp|VF: /apex/getServiceOrder
10:23:55.098 (98646000)|CODE_UNIT_STARTED|[EXTERNAL]|01pR0000000ER63|generateServiceOrder 
10:23:55.098 (98662000)|SYSTEM_MODE_ENTER|true
10:23:55.099 (99360000)|METHOD_ENTRY|[1]|01pR0000000ER63|generateServiceOrder.generateServiceOrder()
10:23:55.099 (99369000)|STATEMENT_EXECUTE|[1]
10:23:55.099 (99465000)|SYSTEM_MODE_ENTER|false
10:23:55.099 (99484000)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:5
10:23:55.099 (99493000)|STATEMENT_EXECUTE|[1]
10:23:55.099 (99501000)|SYSTEM_MODE_EXIT|false
10:23:55.099 (99510000)|METHOD_EXIT|[1]|generateServiceOrder
10:23:55.099 (99649000)|VARIABLE_SCOPE_BEGIN|[7]|this|generateServiceOrder|true|false
10:23:55.099 (99678000)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:16
10:23:55.099 (99689000)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:16
10:23:55.099 (99695000)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:16
10:23:55.099 (99707000)|VARIABLE_ASSIGNMENT|[7]|this|{}|0x54ef99a7
10:23:55.099 (99713000)|VARIABLE_SCOPE_BEGIN|[7]|controller|ApexPages.StandardController|true|false
10:23:55.099 (99861000)|VARIABLE_ASSIGNMENT|[7]|controller|"StandardController [null]"|0x3e50ce81
10:23:55.099 (99874000)|STATEMENT_EXECUTE|[1]
10:23:55.099 (99881000)|SYSTEM_MODE_ENTER|false
10:23:55.099 (99886000)|HEAP_ALLOCATE|[3]|Bytes:5
10:23:55.099 (99894000)|STATEMENT_EXECUTE|[3]
10:23:55.099 (99904000)|STATEMENT_EXECUTE|[4]
10:23:55.099 (99910000)|STATEMENT_EXECUTE|[5]
10:23:55.099 (99918000)|SYSTEM_MODE_EXIT|false
10:23:55.099 (99927000)|SYSTEM_MODE_ENTER|false
10:23:55.099 (99932000)|HEAP_ALLOCATE|[5]|Bytes:5
10:23:55.099 (99936000)|STATEMENT_EXECUTE|[7]
10:23:55.099 (99939000)|STATEMENT_EXECUTE|[8]
10:23:55.099 (99961000)|SYSTEM_METHOD_ENTRY|[8]|ApexPages.currentPage()
10:23:55.100 (100010000)|HEAP_ALLOCATE|[8]|Bytes:69
10:23:55.100 (100021000)|SYSTEM_METHOD_EXIT|[8]|ApexPages.currentPage()
10:23:55.100 (100042000)|SYSTEM_METHOD_ENTRY|[8]|System.PageReference.getParameters()
10:23:55.100 (100057000)|HEAP_ALLOCATE|[8]|Bytes:44
10:23:55.100 (100098000)|SYSTEM_METHOD_EXIT|[8]|System.PageReference.getParameters()
10:23:55.100 (100106000)|HEAP_ALLOCATE|[8]|Bytes:2
10:23:55.100 (100127000)|SYSTEM_METHOD_ENTRY|[8]|MAP.get(ANY)
10:23:55.100 (100144000)|HEAP_ALLOCATE|[8]|Bytes:15
10:23:55.100 (100150000)|SYSTEM_METHOD_EXIT|[8]|MAP.get(ANY)
10:23:55.100 (100160000)|VARIABLE_SCOPE_BEGIN|[8]|servOrder|String|false|false
10:23:55.100 (100170000)|VARIABLE_ASSIGNMENT|[8]|servOrder|"a0HR0000006AAyH"
10:23:55.100 (100174000)|STATEMENT_EXECUTE|[10]
10:23:55.100 (100180000)|HEAP_ALLOCATE|[10]|Bytes:196
10:23:55.100 (100200000)|HEAP_ALLOCATE|[10]|Bytes:7
10:23:55.100 (100225000)|HEAP_ALLOCATE|[10]|Bytes:-4
10:23:55.100 (100699000)|SOQL_EXECUTE_BEGIN|[10]|Aggregations:0|select Product__r.Name, Product_Content__c, Service_Time__c, Quantity__c, Unit_Price__c, Total_Net__c from Selected_Product__c where Service_Reservation__c = :tmpVar1 order by Service_Time__c desc
10:23:55.121 (121120000)|SOQL_EXECUTE_END|[10]|Rows:1
10:23:55.121 (121149000)|HEAP_ALLOCATE|[10]|Bytes:8
10:23:55.121 (121163000)|HEAP_ALLOCATE|[10]|Bytes:409
10:23:55.121 (121216000)|HEAP_ALLOCATE|[10]|Bytes:413
10:23:55.121 (121252000)|METHOD_ENTRY|[10]|01pR0000000ER63|generateServiceOrder.__sfdc_entries(LIST)
10:23:55.121 (121283000)|HEAP_ALLOCATE|[3]|Bytes:16
10:23:55.121 (121298000)|HEAP_ALLOCATE|[3]|Bytes:16
10:23:55.121 (121306000)|HEAP_ALLOCATE|[3]|Bytes:16
10:23:55.121 (121316000)|VARIABLE_ASSIGNMENT|[-1]|this|{}|0x54ef99a7
10:23:55.121 (121357000)|VARIABLE_ASSIGNMENT|[-1]|value|[{"Quantity__c":2,"Product__r":{"Name":"Cocktailbuffet 3","CurrencyIsoCode":"EUR","Id":"a0LR0000002CQ79MAG"},"CurrencyIsoCode":"EUR","Service_Time__c":"10:15","Product_Content__c":"This is an abstract  (30 more) ...","Product__c":"a0LR0000002CQ79MAG","Unit_Price__c":20.00,"Id":"a0MR0000002Hw3EMAS","Total_Net__c":40.00}]|0x1c9c7804
10:23:55.121 (121396000)|VARIABLE_ASSIGNMENT|[3]|this.entries|[{"Quantity__c":2,"Product__r":{"Name":"Cocktailbuffet 3","CurrencyIsoCode":"EUR","Id":"a0LR0000002CQ79MAG"},"CurrencyIsoCode":"EUR","Service_Time__c":"10:15","Product_Content__c":"This is an abstract  (30 more) ...","Product__c":"a0LR0000002CQ79MAG","Unit_Price__c":20.00,"Id":"a0MR0000002Hw3EMAS","Total_Net__c":40.00}]|0x54ef99a7
10:23:55.121 (121410000)|METHOD_EXIT|[10]|01pR0000000ER63|generateServiceOrder.__sfdc_entries(LIST)
10:23:55.121 (121417000)|STATEMENT_EXECUTE|[20]
10:23:55.121 (121427000)|HEAP_ALLOCATE|[20]|Bytes:125
10:23:55.121 (121483000)|HEAP_ALLOCATE|[20]|Bytes:-4
10:23:55.121 (121803000)|SOQL_EXECUTE_BEGIN|[20]|Aggregations:0|select SUM(Total_Net__c) tmp from Selected_Product__c where Service_Reservation__c = :tmpVar1 group by Service_Reservation__c
10:23:55.126 (126552000)|SOQL_EXECUTE_END|[20]|Rows:1
10:23:55.126 (126580000)|HEAP_ALLOCATE|[20]|Bytes:8
10:23:55.126 (126589000)|HEAP_ALLOCATE|[20]|Bytes:19
10:23:55.126 (126614000)|HEAP_ALLOCATE|[20]|Bytes:23
10:23:55.126 (126635000)|METHOD_ENTRY|[20]|01pR0000000ER63|generateServiceOrder.__sfdc_total(LIST)
10:23:55.126 (126654000)|HEAP_ALLOCATE|[4]|Bytes:16
10:23:55.126 (126671000)|HEAP_ALLOCATE|[4]|Bytes:16
10:23:55.126 (126679000)|HEAP_ALLOCATE|[4]|Bytes:16
10:23:55.126 (126689000)|VARIABLE_ASSIGNMENT|[-1]|this|{"entries":"0xefa6b8c2"}|0x54ef99a7
10:23:55.126 (126706000)|VARIABLE_ASSIGNMENT|[-1]|value|[{"tmp":40.0}]|0x1bdf08ad
10:23:55.126 (126723000)|VARIABLE_ASSIGNMENT|[4]|this.total|[{"tmp":40.0}]|0x54ef99a7
10:23:55.126 (126734000)|METHOD_EXIT|[20]|01pR0000000ER63|generateServiceOrder.__sfdc_total(LIST)
10:23:55.126 (126739000)|STATEMENT_EXECUTE|[24]
10:23:55.126 (126746000)|HEAP_ALLOCATE|[24]|Bytes:51
10:23:55.126 (126757000)|METHOD_ENTRY|[24]|01pR0000000ER63|generateServiceOrder.__sfdc_total()
10:23:55.126 (126800000)|HEAP_ALLOCATE|[4]|Bytes:16
10:23:55.126 (126816000)|HEAP_ALLOCATE|[4]|Bytes:16
10:23:55.126 (126824000)|HEAP_ALLOCATE|[4]|Bytes:16
10:23:55.126 (126837000)|VARIABLE_ASSIGNMENT|[-1]|this|{"entries":"0xefa6b8c2","total":"0x4045c136"}|0x54ef99a7
10:23:55.126 (126853000)|METHOD_EXIT|[24]|01pR0000000ER63|generateServiceOrder.__sfdc_total()
10:23:55.126 (126875000)|SYSTEM_METHOD_ENTRY|[24]|String.valueOf(Object)
10:23:55.126 (126896000)|HEAP_ALLOCATE|[24]|Bytes:28
10:23:55.126 (126903000)|SYSTEM_METHOD_EXIT|[24]|String.valueOf(Object)
10:23:55.126 (126916000)|HEAP_ALLOCATE|[24]|Bytes:79
10:23:55.126 (126928000)|SYSTEM_METHOD_ENTRY|[24]|System.debug(ANY)
10:23:55.126 (126938000)|USER_DEBUG|[24]|DEBUG|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%(AggregateResult:{tmp=40.0})
10:23:55.126 (126944000)|SYSTEM_METHOD_EXIT|[24]|System.debug(ANY)
10:23:55.126 (126956000)|SYSTEM_MODE_EXIT|false
10:23:55.126 (126974000)|CODE_UNIT_FINISHED|generateServiceOrder 
10:23:55.146 (146467000)|CODE_UNIT_STARTED|[EXTERNAL]|01pR0000000ER63|generateServiceOrder get(entries)
10:23:55.146 (146488000)|SYSTEM_MODE_ENTER|true
10:23:55.146 (146505000)|CODE_UNIT_STARTED|[EXTERNAL]|01pR0000000ER63|entries
10:23:55.146 (146523000)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:16
10:23:55.146 (146534000)|CODE_UNIT_FINISHED|entries
10:23:55.146 (146539000)|CODE_UNIT_FINISHED|generateServiceOrder get(entries)
10:23:55.159 (159941000)|CODE_UNIT_STARTED|[EXTERNAL]|01pR0000000ER63|generateServiceOrder get(result)
10:23:55.159 (159957000)|SYSTEM_MODE_ENTER|true
10:23:55.159 (159970000)|CODE_UNIT_STARTED|[EXTERNAL]|01pR0000000ER63|result
10:23:55.159 (159981000)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:16
10:23:55.159 (159989000)|CODE_UNIT_FINISHED|result
10:23:55.159 (159994000)|CODE_UNIT_FINISHED|generateServiceOrder get(result)
10:23:55.408 (174135000)|CUMULATIVE_LIMIT_USAGE
10:23:55.408|LIMIT_USAGE_FOR_NS|(default)|
  Number of SOQL queries: 2 out of 100
  Number of query rows: 2 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 0 out of 150
  Number of DML rows: 0 out of 10000
  Number of script statements: 7 out of 200000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 10
  Number of Email Invocations: 0 out of 10
  Number of fields describes: 0 out of 100
  Number of record type describes: 0 out of 100
  Number of child relationships describes: 0 out of 100
  Number of picklist describes: 0 out of 100
  Number of future calls: 0 out of 10

 

:

 

 

TheIntegratorTheIntegrator

I am not able to see

system.debug('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%'+result);

 in the debug log, have you removed it or is the getResult() function not being called?

 

 

magandrezmagandrez

Hi,

 

The code is still there, I didn't remove anything. I think it is not called at all.

 

MGA.