Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top


Is it possible to leverage relationships with Visualforce remoting, including one object as a property of another?


I've been playing around but always seem to get a VF remoting exception in the console with no useful information:

> Visualforce Remoting Exception:  VFRemote.js:118 $VFRM.Util.error
> VFRemote.js:118 (anonymous function) VFRemote.js:133
> VFRemote.js:52 a.Observable.fireEvent VFRemote.js:47
> _Visualforce.Direct._Visualforce.extend.onProviderData VFRemote.js:87 VFRemote.js:52 a.Observable.fireEvent VFRemote.js:47
> VFRemote.js:95
> _Visualforce.extend.handleResponse VFRemote.js:76 a VFRemote.js:39 (anonymous function)

I'm assuming that it's just not supported and I'm making the type-conversion routines throw a bit of a hissy fit, but it'd be good to know if it's just me doing something stupid.

Rough Code Example

If i Had ObjectA_c and ObjectB_c, where A has a lookup to B, is there a way to pass an instance of ObjectA_c to a remote method with an instance of ObjectB_c going along for the ride?

In the page

function ObjectA__c()
  this.Name = '';
  this.ObjB__r = null;              

function ObjectB__c()
  this.Name = '';


var b = new ObjectB__c();
b.Name = 'New B';

var a = new ObjectA__c();
a.Name = 'New A';
a.ObjB__r = b;

  function(result, event) {

In the controller

global static void UpsertA(ObjectA__c objA)
  upsert objA.ObjB__r;
  upsert objA;
share|improve this question
up vote 3 down vote accepted

It is possible, although I'm not sure what the error message is that you are seeing.

I see an issue in the controller code. The Id reference field needs to be assigned after the first upsert is done.

global static void UpsertA(ObjectA__c objA)
  upsert objA.ObjB__r;
  // Add this line
  objA.ObjB__c = objA.ObjB__r.Id;
  upsert objA;

Here's a gist I put together with stripped down code that has it working.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.