General Category > Help for ParamQuery Pro

Force.com Visualforce RemoteAction

(1/1)

Ron Hess:
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:
[ Only Pro members may read this post. ]

Ron Hess:
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:
[ Only Pro members may read this post. ]

Navigation

[0] Message Index

Go to full version