• SFDevelopers
  • NEWBIE
  • 5 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 3
    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

Hi,

I have a strange situation here.

 

I have written a web service class which searches for MemberID (which is unique) in Accounts, if its found then it updates that record OR else it inserts new record. The values for each fields in Accounts are supplied as a XML string parameter from Java. So the Java program calls this web service methods by passing XML strings.

 

All works well when tested with some static inputs, however when this method called in bulk, I get he error - 

Insert failed. First exception on row 0; first error: DUPLICATE_VALUE, duplicate value found: Member_ID__c duplicates value on record with id: 0019000000CZC83: []

 

I have no clue why and how could this happen? As I am searching for Member_ID__c in my query then inserting if its not found. As an additional step, I replaced 'insert' by 'upsert', still I am getting this exception.