function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
iatschuckiatschuck 

create new record cominbed with different sobject fields

I would like to use javascript function to add a new custom sobject record. But I have a problem to create a new record.
 
I created custom subject, which has a lookup relationship field form other custom sobject. I have following code.
 
var c = new sforce.SObject("sobject1");
c.Name=’AAA’;
c.sobject2.Name=’BBBB’;  
ß this is not allowed
sforce.connection.create([c]);
 
Can anyone please let me know how I can assign value to sobject2 fields?
 
Thanks
CaptainObviousCaptainObvious

You have 2 sobjects: sobject1 and sobject2

 

In order to create a new sobject1 record with the lookup to sobject2, you need to set the Id of sobject2.

 

Assuming that you retrieve the sobject2 id somewhere else in the code, the javascript would then be:

 

var c = new sforce.SObject("sobject1"); c.Name=’AAA’; c.sobject2lookup__c = sobject2.id; sforce.connection.create([c]);

 

where sobject2lookup__c is your lookup relationship field