I posted this to Twitter a couple of times but I'm still stumped.
I have an Apex class called "TestRemoteActionClass" with a method marked as a @RemoteAction that looks something like this:
@RemoteAction
public static List<sObject> insertRecords(List<sObject> records) {
insert records;
return records;
}
In my Visualforce page, I call it like this:
Visualforce.remoting.Manager.invokeAction(
'TestRemoteActionClass.insertRecords',
records,
function(result, event) {
console.log(result);
console.log(event);
}
);
Every time I try this, I get the following error back:
"Please provide an id or sobjectType value"
I understand the issue is related to the RemoteAction method taking a List as parameters, so it would make sense that the method needs some context to describe the SObjectType of the incoming list of records. If I change the "insertRecords" methods to take a concrete SObjectType (Account, Contact, etc), then it works fine.
However, I cannot figure out how to pass an "sobjectType" value with the parameters. I have tried the following as the "records" parameter with the same error:
[{"attributes":{"type":"Account"},"Name":"foo"}]
[{"attributes":{"sobjectType":"Account"}, "Name":"foo"}]
[{"sobjectType":"Account","Name":"foo"}]
In addition, I have tried numerous permutations of uppercase vs. lowercase combos for the 'sobjectType' parameter name. Still no luck.
Can anyone help? This issue is keeping me from creating a List "insert" call via RemoteActions, which would be huge to streamline things.
If this approach is just not possible, please let me know that too!
Best Answer
Looks like this may be a bug that will be fixed soon.
http://boards.developerforce.com/t5/Visualforce-Development/SObject-JS-Remoting-Error-Please-provide-an-id-or-sobjectType/m-p/565745#M60287