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
mauricio.ramos@corpitalmauricio.ramos@corpital 

issue with JS remoting method with parameter

Hello,

 

I am trying to get the AccId of the current page record to pass into (or get it in the method somehow) so that i can use it as a parameter for a query. Basically I have the following code in a VF page:

 

 

  <apex:includeScript id="a" value="https://www.google.com/jsapi" />     
    <script type="text/javascript">
        // Load the Visualization API and the piechart package.
        google.load('visualization', '1.0', {'packages':['corechart']});
        // Set a callback to run when the Google Visualization API is loaded.
        google.setOnLoadCallback(initCharts);

        //load all the charts..
        function initCharts() { 

              var param =  location.search.substring(1);
              var vars = param.split("&");
              var pair = vars[0].split("=");
              
              var aID = pair[1];
              alert (aID);
              //LOAD CASE CHART DATA
              GoogleChartsController.loadChildCases(aId, function(resultCase, event){
                   
                   alert('Data1 set: ' + resultCase);
                  var visualization = new google.visualization.ColumnChart(document.getElementById('caseChart'));
                   alert('div:'+ document.getElementById('caseChart'));
                  var data1 = new google.visualization.DataTable();  
                  data1.addColumn('string', 'Cases');
                  data1.addColumn('number', 'Cases');       
                  //add rows from the remoting results
                  for(var i =0; i < resultCase.length; i++){
                      var r = resultCase[i];
                   // alert('result item:'+r);
                   // alert('result item:'+r.Id + ' - '+  r.expr0);
                      data1.addRow([r.Id, r.expr0]); 
                   }
                    // all done, lets draw the chart with some options to make it look nice.
                    visualization.draw(data1, {legend : {position: 'top', textStyle: {color: 'blue', fontSize: 10}}, width:150,vAxis:{textStyle:{fontSize: 10}},hAxis:{textStyle:{fontSize: 10},showTextEvery:1,slantedText:false}});
              }, {escape:true});
              
          } 
    </script>
        <div id="caseChart" />

 It works fine if I don't pass any parameter to it. but as soon as I add the var aId in the remoting call, it fails miserably! I have also tried to use the Apexpages.currentPage parameters to get the ID but it fails as a null reference.

 

This is the controller code:

 

global with sharing class GoogleChartsController {
 global static Account acc;
 
    public GoogleChartsController(ApexPages.StandardController controller) {
        acc = (Account)controller.getRecord();
        //system.debug('###Acid: ' + acc);
    }


    @RemoteAction   
    global static AggregateResult[] loadChildCases(String aId) {
        system.debug('##Page Param: ' + aId);
        AggregateResult[] caseLst = [Select ParentId, count(Id) FROM Case  Group By ParentId];
        system.debug('##Case Aggregate list: ' + caseLst);
        return caseLst;

    }

 Referencing the static acc account gives null, so I am not sure how to achieve this. Please assist!!