I've called a JS Remoting function on document.ready(). It works fine intermittently. But throws this error in Console when sometimes I come back to a page after a day and it was loaded a fresh:
Uncaught TypeError: Cannot read property 'tid' of undefined VFRemote.js:85
Does having cache=true have any drastic effect on the page where JS Remoting is employed?
Edit: <- Code added below ->
<script type="text/javascript">
$j = jQuery.noConflict();
var mtid = '{!JSINHTMLENCODE(mi)}';
$j(document).ready(function(){
advpm.RemotingController.getListItems(new Date( $j('.s-date').text() ).toUTCString(), new Date( $j('.e-date').text() ).toUTCString(), mtid, $j('.opt1').is(':checked'), $j('.opt2').is(':checked'), $j('.opt3').is(':checked'), $j('.opt4').is(':checked'), $j('.opt5').is(':checked'), function(result, event){
if (event.status && result){
//do something with result here...
} else {
//error added to page here...
}
}, {escape:true});
});
</script>
APEX Method code:
@ReadOnly @RemoteAction
global static list<wListItems> getListItems(Date da0, Date da1, string matId, boolean showEvents, boolean showMyActivitiesOnly, boolean showMyMTOnly, boolean showActivitiesWithMTOnly, boolean showRelatedMT)
{
list<wListItems> allitems = new list<wListItems>();
Datetime frmDt = Datetime.newInstance(da0.year(), da0.month(), da0.day());
Datetime toDt = Datetime.newInstance(da1.year(), da1.month(), da1.day());
if (showEvents)
{
list<Event> eventsList = new list<Event>();
string qry = 'select Id, Subject, WhatId, What.Name, ActivityDate, StartDateTime, EndDateTime, IsAllDayEvent, Owner.FirstName, Owner.LastName from Event where ActivityDate >= '+frmDt.format('yyyy-MM-dd')+' and ActivityDate <= '+toDt.format('yyyy-MM-dd')+(showMyActivitiesOnly == true ? ' and OwnerId = \''+ Userinfo.getUserId() +'\'' : '')+(matId != null && matId != '' ? ' and WhatID =: matId' : (showActivitiesWithMTOnly == true ? ' and WhatID IN (select Id from Case) and What.Type = \'Case\'' : '')+' order by StartDateTime');
for(Event e : (list<Event>)database.query(qry))
{
allitems.add( new wListItems(e.Id,e.Subject,'',e.ActivityDate,'Event','') );
}
}
return allitems;
}
This call when viewed in Chrome Console (the request headers):
action: "advpm.RemotingController"
ctx: {,…}
data: [Sun, 27 Jul 2014 00:00:00 GMT, Sun, 3 Aug 2014 00:00:00 GMT, , true, false, false, false, true]
method: "getListItems"
tid: 5
type: "rpc"
The parameters view in Chrome Console:
0: "Sun, 27 Jul 2014 00:00:00 GMT"
1: "Sun, 3 Aug 2014 00:00:00 GMT"
2: ""
3: true
4: false
5: false
6: false
7: true
Chrome Console "Preview" tab - http://screencast.com/t/wJMB4ixwx:
action: "Unknown"
data: ""
message: "Remoting request invalid for your session. Refresh page and re-submit request"
method: "Unknown"
ref: false
statusCode: 402
type: "exception"
vfDbg: true
vfTx: true
where: ""
and the dreaded Console Exception logged - http://screencast.com/t/pDFZQqJ6F9:
Uncaught TypeError: Cannot read property 'tid' of undefined VFRemote.js:85
VFExt3.Direct.VFExt3.extend.getTransaction VFRemote.js:85
VFExt3.Direct.RemotingEvent.VFExt3.extend.getTransaction VFRemote.js:88
(anonymous function) VFRemote.js:131
a.Event.fire VFRemote.js:52
a.Observable.fireEvent VFRemote.js:47
VFExt3.direct.RemotingProvider.VFExt3.extend.onData VFRemote.js:94
VFExt3.extend.handleResponse VFRemote.js:75
a VFRemote.js:39
(anonymous function) VFRemote.js:40
