• Peter-Noges
  • NEWBIE
  • 0 Points
  • Member since 2015


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies

The salesforce.com docs states remoting methods can take the following values as arugments, "primitives, collections, typed and generic sObjects, and user-defined Apex classes...". There appears to be an issue with generic sObject. Take a look at the following Visualforce page and the related remoting method.

 

<apex:page showHeader="true" sidebar="true" controller="RemotingSObject">
	<input value="Click Me" onclick="doRemote();" type="button"/>

	<script type="text/javascript">
		
		function doRemote(){
			var obj = {
				sobjectType: 'Account',
				Name: 'My new account'
			};

			//You can see there is a value of sbojectType set
			console.log(obj);

			Visualforce.remoting.Manager.invokeAction('{!$RemoteAction.RemotingSObject.receiveSObject}', obj, function(result, event){
		        console.log(event);
		        console.log(result);
			});
		}

	</script>
</apex:page>

 The Class:

public with sharing class RemotingSObject {
	@RemoteAction
	public static void receiveSObject(SObject obj) {
		system.debug(obj); 
	}
}

 If you look in the browsers JavaScript console you will see this error message:

Visualforce Remoting Exception: Unable to determine SObject type: SObject. Please provide an 'id' or 'sobjectType' value.

 

Makes no sense as an sobjectType value is being supplied. Oddly enough if you provide an id value it works...but if you are trying to insert a new sObject you do not yet have an id value to use.

 

Any ideas on how to make this work? Bug?

 

Thanks,

Jason

 

  • February 05, 2013
  • Like
  • 1