You need to sign in to do that
Don't have an account?
banderson5144Dev
Visualforce Remoting Javascript sObject
Can someone please provide me with Sample Code to create a Javascript Sobject for VF remoting? Here's what I have so far and it doesnt work:
Page:
<apex:page showHeader="false" standardStylesheets="false" sidebar="false" doctype="html-5.0" controller="testVFRemote"> <input type="button" onclick="myFunc();" value="Click Me"/> <script type="text/javascript"> function myFunc() { var vfRemoteVar = {sobjectType:"Account",Name:"My New Account"}; Visualforce.remoting.Manager.invokeAction( '{!$RemoteAction.testVFRemote.insAcct}', vfRemoteVar, function(result, event){ alert(result); alert(event); }, {escape: true} ); } </script> </apex:page>
Controller:
public with sharing class testVFRemote { @RemoteAction public static Database.Saveresult insAcct(sObject sobj) { return Database.insert(sobj); } }
heres the error i am getting:
Visualforce Remoting Exception: Unable to determine SObject type: SObject. Please provide an 'id' or 'sobjectType' value.
Anyone?
Come on I know i am not the only one who must have asked this question before.
Try this code for controller
I just get this now for the error:
Visualforce Remoting Exception:
Please, provide complete error stack so that we can help you.
Request:
Response:
This is realy strange. I will try to reproduce at my side. Is there any required field on your Account object, which we are missing?
Nope. Just a basic dev account. I have used VF remoting to pass in strings and other data types. But i wanted to try passing in sObjects.
So I have partially solved my problem. Instead of using a Generic sObject type, I am defining a concrete sObject type of Account. I am also leveraging the AJAX toolkit (don't know if its absolutely necessary, so someone can tell me otherwise) to create the Account sObject variable in Javascript for me. Here is my code and the data being sent back and forth
Controller:
VF Page:
Request Data:
Response Data:
Although this does solve my immediate problem, I would still like to get the generic sObject function working so I am not marking this solved yet.