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
NishaCNishaC 

Button Click in javascript Remoting

Button Click is not working 

i am using @remoteaction 

actually what i want is when i am selecting Date From and Date To and click on GO button it should show me result according to the dates

 

Visualforce Page:

<apex:page controller="DashPortalController" sidebar="false">
<apex:pageMessages ></apex:pageMessages>
<!-- Google API inclusion -->
<apex:includeScript id="a" value="https://www.google.com/jsapi" />
<apex:sectionHeader title="Google Charts" subtitle="Chart 1"/>

<!-- Google Charts will be drawn in this DIV -->
<apex:form >

<table align="center">
<td><b>Date From:</b>
<apex:inputField value="{!servList.Service_Start_Date__c}" /></td>
<td><b>Date To:</b>
<apex:outputText value="{0,date,dd/MM/yyyy}">
<apex:param value="{!NOW()}" />
</apex:outputText></td>
<td><input type="button" onclick="initCharts()" value="Go"/></td>

</table>
<div id="chartBlock" style="width: 600px; height: 500px;"/>

<script type="text/javascript">
google.load('visualization', '1', {'packages':['corechart']});
google.setOnLoadCallback(initCharts);

function initCharts() {
DashPortalController.loadCustomerServiceSuccessRate(
function(result, event){
// load Column chart
var visualization = new google.visualization.PieChart(document.getElementById('chartBlock'));
var data = new google.visualization.DataTable();
data.addColumn('string','Success or Failure');
data.addColumn('number','Percentage');

var finalBean= result;
data.addRows([

['Service Success Rate', finalBean.totalServiceColl],
['Service Failure Rate', finalBean.totalCases]]);


visualization.draw(data,{title:'Service Success Rate',legend : {position: 'bottom', textStyle: {color: 'blue', fontSize: 10}}, width:window.innerWidth,vAxis:{textStyle:{color:'red', fontSize: 15}}});
}, {escape:true});
}
</script>
</apex:form>
</apex:page>

 

Controller Coding:

 

global with sharing class DashPortalController{

public Service__c servList{get;set;}


@RemoteAction
global static CaseFailBean loadCustomerServiceSuccessRate(){

Map<Id,CaseFailBean> caseBeanMap=new Map<Id,CaseFailBean>();

map<id,Decimal> mapgrandParentsCounts = new map<id,Decimal>();
Service__c serviceList= [select id,Name,Service_Start_Date__c,Last_90_Days__c,
Last_Month__c,Last_Week__c,Last_Year__c
from Service__c s where Status__c = 'Active'
AND Customer__c!=null limit 1];
Date Last90days= serviceList.Last_90_Days__c;
Date LastWeek= serviceList.Last_Week__c;
Date LastMonth= serviceList.Last_Month__c;
Date LastYear= serviceList.Last_Year__c;
Date DateFrom= serviceList.Service_Start_Date__c;

List<Service__c> sr2= [select id, Name, Customer__c,Status__c, s.Customer__r.Grand_Parent_Account__c,
Week_Number__c,Count_of_Pickup_Days__c,Service_Start_Date__c
from Service__c s where Status__c = 'Active'
AND Count_of_Pickup_Days__c!=null AND Customer__c!=null AND Week_Number__c!=null
AND Service_Start_Date__c>=:LastMonth] ;

List<service__c> srList= [select id, Name, Customer__c,Status__c, s.Customer__r.Grand_Parent_Account__c,
Week_Number__c,Count_of_Pickup_Days__c,Service_Start_Date__c
from Service__c s where Status__c = 'Active'
AND Count_of_Pickup_Days__c!=null AND Customer__c!=null AND Week_Number__c!=null
AND Service_Start_Date__c>=:LastYear];

if(DateFrom>=LastYear){
for(Service__c sr:srList){
if(mapgrandParentsCounts.containskey(sr.Customer__r.Grand_Parent_Account__c) && sr.Name!=null)
{
Decimal tCount = mapgrandParentsCounts.get(sr.Customer__r.Grand_Parent_Account__c);
tCount = tCount + (sr.Count_of_Pickup_Days__c * sr.Week_Number__c);
mapgrandParentsCounts.put(sr.Customer__r.Grand_Parent_Account__c,tCount);
}
else
{
mapgrandParentsCounts.put(sr.Customer__r.Grand_Parent_Account__c,(sr.Count_of_Pickup_Days__c * sr.Week_Number__c));
}
}
}


List<Service__c> sr1 = [select id, Name, Customer__c,Status__c, s.Customer__r.Grand_Parent_Account__c,
Week_Number__c,Count_of_Pickup_Days__c,Service_Start_Date__c
from Service__c s where Status__c = 'Active'
AND Count_of_Pickup_Days__c!=null AND Customer__c!=null AND Week_Number__c!=null
AND Service_Start_Date__c>=:Last90days];
system.debug('========sr1=========='+sr1);
if(DateFrom>=Last90days){
for(Service__c srObj: sr1){
if(mapgrandParentsCounts.containskey(srObj.Customer__r.Grand_Parent_Account__c) && srObj.Name!=null)
{
Decimal tCount = mapgrandParentsCounts.get(srObj.Customer__r.Grand_Parent_Account__c);
tCount = tCount + (srObj.Count_of_Pickup_Days__c * srObj.Week_Number__c);
mapgrandParentsCounts.put(srObj.Customer__r.Grand_Parent_Account__c,tCount);
}
else
{
mapgrandParentsCounts.put(srObj.Customer__r.Grand_Parent_Account__c,(srObj.Count_of_Pickup_Days__c * srObj.Week_Number__c));
}
}
}else if(DateFrom>=LastMonth){
for(Service__c srObj1: sr2){
if(mapgrandParentsCounts.containskey(srObj1.Customer__r.Grand_Parent_Account__c) && srObj1.Name!=null)
{
Decimal tCount = mapgrandParentsCounts.get(srObj1.Customer__r.Grand_Parent_Account__c);
tCount = tCount + (srObj1.Count_of_Pickup_Days__c * srObj1.Week_Number__c);
mapgrandParentsCounts.put(srObj1.Customer__r.Grand_Parent_Account__c,tCount);
}
else
{
mapgrandParentsCounts.put(srObj1.Customer__r.Grand_Parent_Account__c,(srObj1.Count_of_Pickup_Days__c * srObj1.Week_Number__c));
}
}
}




CaseFailBean beanList=new CaseFailBean();

for(id gpAcc : mapgrandParentsCounts.keyset()) {

system.debug('==========ServiceSuccessRate========='+ServiceSuccessRate);
system.debug('==========ServiceFailureRate========='+ServiceFailureRate);
CaseFailBean beanObj=new CaseFailBean(ServiceSuccessRate,ServiceFailureRate);
beanList=beanObj;

}

system.debug('==========beanList=========='+beanList);
return beanList;
}

global class CaseFailBean{
public Decimal totalCases{get;set;}
public Decimal totalServiceColl{get;set;}


public CaseFailBean(Decimal ServiceSuccessRate,Decimal ServiceFailureRate){
this.totalServiceColl=ServiceSuccessRate;
this.totalCases=ServiceFailureRate;
}

public CaseFailBean(){

}
}
}

 

 

 

Saravanan @CreationSaravanan @Creation

decleare  the initCharts()  java script function outside the <apex:form> tag .

 

and check it in debug log after clicked the bottuon.


NishaCNishaC

i have declared it but nthing happens

<apex:form >

<table align="center">
<td><b>Date From:</b>
<apex:inputField value="{!servList.Service_Start_Date__c}" /></td>
<td><b>Date To:</b>
<apex:outputText value="{0,date,dd/MM/yyyy}">
<apex:param value="{!NOW()}" />
</apex:outputText></td>
<td><input type="button" onclick="initCharts()" value="Go"/></td>

</table>
</apex:form>

 

now what i want is to get date which i have selected in Date From in Vf

global with sharing class DashPortalController{

                  public Service__c servList{get;set;}


@RemoteAction
global static CaseFailBean loadCustomerServiceSuccessRate(){

//i want to get the selected date here with this

but it gives me error nd cant use servList in this @remoteaction

 

Date DateFrom= servList.Service_Start_Date__c;

 

any idea how i get that date which i have selected in vf in controller page

Saravanan @CreationSaravanan @Creation

Hi Nisha ,

 

Did you checked in the developer console after clicked on the button .

 

any log is captured or not  ,if it capture then definitly some method is calling.

NishaCNishaC

how to check debug of vf page for javascript

Saravanan @CreationSaravanan @Creation

if you are using Chrome properties-->Tools-->javaScript Console

 

if you are using firefox Tools-->web Developer-->web Cinsole or Error Console

 

and check ur force.com developerconsole too after clicked the button ,because if any log is captured then we can get to know some controller action is taking place

 

NishaCNishaC

<td> Date<br></br><input id="t" name="datee" onfocus="DatePicker.pickDate(false,

't', false);" size="12" tabindex="28" type="text" /></td>

 

 I am not able to pass the selected date to the apex controller.. could you help me on this :)

 

Saravanan @CreationSaravanan @Creation
Sumit@TCSSumit@TCS

Best way to track java script error is to instal Firebug1.11.1

 

Its free try it out....

 

Thanks

Sumit Kumar