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
Ramona McCookRamona McCook 

Use List button to pass parameter to @RemoteAction in Visualforce page controller

Would someone please help me pass that ID from the current object to a controller's @RemoteAction using a detail list button?
I have tried System.currentPageReference().getparameters().get() but that doesn't work within @RemoteAction

The following is my controller, where I need my SELECT statement to filter by the objectID from which the custom detail button is pressed :
global with sharing class googlegantchartscope {  

public String oppList { get; set; }
    
@RemoteAction
global static Cluster__c[] loadrecords() {
    /*String testID = {!$currentpage.parameters.marketID}; 'a0Sc0000003GHNC'; System.currentPageReference().getparameters().get('marketID');*/
    
    return [select Name, Gantt_Chart_Name__c, Design_Completed__c, Estimated_Permit_Approval_Completion__c, Duration__c, Percent_Complete__c, Dependencies__c from Cluster__c where Design_Completed__c!=Null AND Market__c = :needCustomObjectIDFromDetailButtonHere];}
}

Visualforce Page:
<apex:page controller="googlegantchartscope">
<apex:includeScript id="a" value="https://www.google.com/jsapi" />
<apex:sectionHeader title="Google Charts + Javascript Remoting" subtitle="Demo of Cluster Scheduling" />
<div id="chart_div" />
    

<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
 <script type="text/javascript">
 <!--loads the visualization in gant chart view-->
 google.charts.load('current', { 'packages': ['gantt']});
 google.charts.setOnLoadCallback(InitCharts);
  
 function InitCharts() {
 <!-- calls the function called 'loadrecords' in googlegantchart controller-->
 googlegantchartscope.loadrecords( 
     
 <!-- following the usual remoting syntax-->
 function(result, event) {
 
 var visualization = new google.visualization.Gantt(document.getElementById('chart_div'));
 <!--adding data to Chart-->
 var data = new google.visualization.DataTable();<!-- variable declaration-->
  
 data.addColumn('string', 'Cluster');
 data.addColumn('string','Cluster and Priority');
 data.addColumn('date', 'Design Completed');
 data.addColumn('date', 'Est Permit Approval Completion');
 data.addColumn('number', 'Duration');
 data.addColumn('number', 'Percent Complete');
 data.addColumn('string', 'Dependencies'); 
 
 for (var i = 0; i < result.length; i++) {
 var r = result[i];
     /*data.addRow([r.Task_Id__c, r.Task_Name__c, new Date(r.Start_Date__c), new Date(r.End_Date__c), r.Duration__c,r.Percent_Complete__c,r.Dependencies__c]);*/
     data.addRow([r.Name, r.Gantt_Chart_Name__c, new Date(r.Design_Completed__c), new Date(r.Estimated_Permit_Approval_Completion__c), r.Duration__c, r.Percent_Complete__c, r.Dependencies__c]);
 }
 var options = {
 height: i*50,
 gantt: {
 criticalPathEnabled:true
 }
 };
 visualization.draw(data, options);<!-- draws a table that contains the result of data-->
 },{escape:true});
 }
 </script>
 
</apex:page>


 
Best Answer chosen by Ramona McCook
AngrySlothAngrySloth
You could use the visualforce {!$CurrentPage.parameters.marketId} and then pass that into your remoteAction apex method.
 
VISUALFORCE PAGE

<script type="text/javascript">

   var marketId = "{!$CurrentPage.parameters.marketID}";
   console.log( 'your marketID should be ' + marketId);

    <!--loads the visualization in gant chart view-->
     google.charts.load('current', { 'packages': ['gantt']});
     google.charts.setOnLoadCallback(InitCharts);

function InitCharts() {
 <!-- calls the function called 'loadrecords' in googlegantchart controller-->
 googlegantchartscope.loadrecords( marketId, 
      
 <!-- following the usual remoting syntax-->
 function(result, event) {
 
APEX CONTROLLER

@RemoteAction
global static Cluster__c[] loadrecords( String marketId ) {
Hope this helps.
 

All Answers

AngrySlothAngrySloth
You could use the visualforce {!$CurrentPage.parameters.marketId} and then pass that into your remoteAction apex method.
 
VISUALFORCE PAGE

<script type="text/javascript">

   var marketId = "{!$CurrentPage.parameters.marketID}";
   console.log( 'your marketID should be ' + marketId);

    <!--loads the visualization in gant chart view-->
     google.charts.load('current', { 'packages': ['gantt']});
     google.charts.setOnLoadCallback(InitCharts);

function InitCharts() {
 <!-- calls the function called 'loadrecords' in googlegantchart controller-->
 googlegantchartscope.loadrecords( marketId, 
      
 <!-- following the usual remoting syntax-->
 function(result, event) {
 
APEX CONTROLLER

@RemoteAction
global static Cluster__c[] loadrecords( String marketId ) {
Hope this helps.
 
This was selected as the best answer
Ramona McCookRamona McCook
AngrySloth, thank you so much! I have literally wrecked my brain trying to accomplish this! I appreciate it! 
AngrySlothAngrySloth
My pleasure, hope your brain recovers from the wrecking