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)}';
        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});

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
  • can you post your whole code? – Mohith Shrivastava Aug 2 '14 at 6:22
  • @Mohith - I've added code and relevant Debug info that I've been receiving at my end in chrome. The thing is, as soona s I [ress F5 while console is ON, it gets resolved and no error and my call works ok. Then when I most of the time close my browser, and then come back again after login it comes back. Also, I didn't get it, the most troubling part, why does the "Preview" of Remoting call shows Something different error than what JS Console shows ... – VarunC Aug 2 '14 at 8:08
  • Can you post apex method code? – Ashwani Aug 2 '14 at 8:28
  • sry forgot to add that earlier, APEX class code added as well now. – VarunC Aug 2 '14 at 8:55
  • Based on stackoverflow.com/questions/21614184/…, the problem is likely to relate to the remote method arguments. I suggest you check all of them in the JavaScript: you can console.log them or use the JavaScript debugger: see e.g. salesforce.stackexchange.com/questions/36715/…. – Keith C Aug 2 '14 at 9:18

It's been long sine this question has been posted but still writing in case any future readers. The key here is to add { buffer: false, escape: true, timeout: 30000 }

What this line does is it will not allow remote manager wouldn't to batch up the remoting calls. Why this is helpful because sometimes we just don't have data to pass to a remoting function when bootstrapping happens for JS code resulting in undefined objects being passed to remoting calls and thus the the above error.

Incase wondering where to add it:

scope.getParentId = function() {

        EsignCongaSigningUrlRemoting.getEsignUrlParentIdFromObjectId($scope.objectId, 1, function(response, event) {
            if(event.status) {
                console.log('parentId in response = ',response);
                $scope.parentId = response;

            else {
                $scope.parentId = '';

        },{ buffer: false, escape: true, timeout: 30000 }); 

| improve this answer | |

Came through same issues. Hope the answer below helps others.

There can be multiple issues here, related to one thing: RemoteAction. It can be:
- Static Resource contains the RemoteAction
- Accessing remoteAction from different package may be
- RemoteAction not defined

So, please look for issue related to RemoteAction to fix this.

| improve this answer | |

From my recent experience, this was because my remoting function was no longer on the page (so not defined). I had written a messy script that was removing references to it and then calling it.

| improve this answer | |

Disabling buffering can definitely help depending on what operations you're performing, but in a large code base this can also get unwieldy. It seems that it is a case of bad parameters that generally causes this, but if you've got a lot of requests being bundled together (17 in my instance) then updating all of them not to buffer to find the culprit may not be desirable.

I managed to find the culprit in my code by putting a break point on line 2070 of VFremote.js:

combineAndSend: function() {
    var d = this.callBuffer.length; // break on this line

If your calls are buffered, then by inspecting this.callBuffer you can see the list of pending calls, along with the data that will be passed to them:

List of remoting calls to be called

By checking the data member for each call you should be able to locate the one that has a dreaded undefined where real data should be.

(Interestingly I seem to have some double-ups in this list, will have to investigate if they're evaluated on the backend more than once given they have no parameters and are read-only operations).

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.