Author Topic: Force.com Visualforce RemoteAction  (Read 4984 times)

Ron Hess

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 19
    • View Profile
Force.com Visualforce RemoteAction
« on: October 10, 2013, 09:15:01 pm »
I've resolved a tricky bit of debugging, and would share it with users of Force.com platform & ParamQuery

If you are using @RemoteAction methods in your controller to return data to your PQ grid, it works quite well ( related records and all), i can pass the entire JSON array into the grid data model and it all shows up.

the problem is when you edit a row, some of the data ( related objects ) are actually shared memory in the client and edit's on one row can change all the other rows that share that related object. 

This is only an issue if you return fields from related lookups in your JSON.

the fix is to clone the array ( and objects in the array) when you get the data back from your RemoteAction.

i use :

function remotingCallback( result, event)
    {               
        checkErrors( event);
       
        // important, we must unpack the JSON we get from Visualforce, it uses serRefId to avoid sending duplicate
        // copies of identical data, but WE NEED separate data to allow edits on one row to not change other rows...
        result = deepCloneObject( result); 

...
       obj.dataModel = { data: result.lines, paging: 'local' };


paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6309
    • View Profile
Re: Force.com Visualforce RemoteAction
« Reply #1 on: October 11, 2013, 12:08:04 am »
Thanks for sharing.

It appears that your message got truncated; I've increased the post character limit.  :)
« Last Edit: October 11, 2013, 12:58:57 am by paramquery »

Ron Hess

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Force.com Visualforce RemoteAction
« Reply #2 on: October 11, 2013, 12:29:19 am »
the main thing is that Force.com Visualforce developers should deepClone records they get back from their RemoteAction methods ( JSON) unless their data is completely flat ( no related info )

i'l attach my deepClone, it's just a javascript clone i picked from stack-exchange


paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6309
    • View Profile
Re: Force.com Visualforce RemoteAction
« Reply #3 on: October 14, 2013, 02:17:55 pm »
a point to add:

All internal pqgrid row properties begin with pq_ so it's easier to exclude them in a single statement.

if ( attr.indexOf( "pq_" ) == 0 ){
  continue;
}