VF remoting exception: unexpected token: FROM

  • 1
  • Problem
  • Updated 3 years ago
We're getting a strange error. Looks like this:


Here's the console:


This occurs after adding a row or rows to a model in a page include, and then attempting a save (or perhaps just trying to run anything in javascript?). The save works, but the error is thrown.

If I refresh the page, the error is gone and doesn't return.

Any idea what might be happening here?
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb

Posted 3 years ago

  • 1
Photo of Irvin Waldman

Irvin Waldman, Champion

  • 9,006 Points 5k badge 2x thumb
Thinking out loud: Obviously some sort of parsing error.  Maybe open developer tools and inspect your models and their related SOQL statements.  The "FROM" is interesting.  
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
Irvin,

Quite right. I'll try to take a look at .soql and see if there's anything noticeable.
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
Ok,

So I've narrowed it down to this:

I have a model (in a page include) which has a single field, that field being a ui-only field.

I get the error when a save is attempted on that model.
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
The problem is that I have been using something like this:

skuid.model.save(skuid.model.map());

And if the model described above has changes, that causes a problem.

I tried the following, but it completely removed the model from the client:

var modelsToSave = skuid.model.map();	
delete modelsToSave['AddTests'];
skuid.model.save(modelsToSave);

How can I tell skuid to save all models that have changes except a certain model... or to never attempt to save a certain model?

On the other hand, it seems like this error shouldn't be being thrown in the first place, because there are no unsaved changes that need to be sent back to the database....

Skuid?
(Edited)
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
I suppose I could to this, but it seems like such a long way around...

var modelsToSave = [];
$.each(skuid.model.map(), function(){
if (this.hasChanged && this.id !== 'AddTests') {
modelsToSave.push(this);
}
})
skuid.model.save(modelsToSave);
Photo of Ben Hubbard

Ben Hubbard, Employee

  • 12,470 Points 10k badge 2x thumb
skuid.model.map() returns an object keyed of of the model ids. the skuid.model.save api takes an array. So basically, you're sending the wrong "type" (if you can say that in Javascript) as a parameter into the api. skuid.model.list() should work just fine though as long as you're ok with saving in the order that skuid.model.list() returns the models.
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
Ben,

Interesting.

skuid.model.save(skuid.model.map()); has been working for me. In fact, it still works as long as my 'AddTests' model doesn't have unsaved changes.

I'll try the .list() method.
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
Regardless of how I attempt the save, I'm getting the error when a save is attempted on the AddTests model.

skuid.model.save(skuid.model.map());
skuid.model.save(skuid.model.list());
skuid.$M('AddTests').save();

All produce the error when skuid.$M('AddTests').hasChanged === true.

The model has only a single ui-only field. Skuid should not try to save changes to the database when the only changes are to ui-only fields.
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
Hey Skuid!

Any update on this? Anytime I try to save a model that has ONLY ui-only fields, I get this unexpected FROM error.
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
Here's a model with exclusively ui-only fields.


I'd like to be able to add and remove rows, and 'save' any changes (so they appear saved in the ui).

But I keep running into this unexpected FROM issue when I try to save, also now coupled with 'Cannot read property 'registeredFieldsByRowThenField' of undefined':


I have a table of about 20 rows in this model, and I need to be able to add and remove rows.
I can't mark a row for deletion and save the model to remove the row, because I get this error.
I tried to use a row action with  "remove context row" (which I think is equivalent to abandonRow()? ), but it removed ALL the rows from the model? Perhaps because they're not saved?

Thoughts on how to accomplish this?

What are best practices for creating a 'ui-only' model?