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
Robert ZentgrafRobert Zentgraf 

Button with Javascript to create new object with child objects

Hello,

I created a button on a custom object to create a new object. For this new copied object I want to create copied child objects, but this is not working and I received following error (Sandbox cs14):
{errors:message:'sObject type 'sObject' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name. Please reference your WSDL or the describe call for the appropriate names.', statusCode:'INVALID_TYPE',}, id:null, success: 'false',}

{!REQUIRESCRIPT("/soap/ajax/31.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/31.0/apex.js" )}
var new_project = new sforce.SObject("Project__c");
//some assignment => is working
result = sforce.connection.create([new_project]);

var query = sforce.connection.query("SELECT RecordType.Id, Recordtype.Name, Employee__c, Employee__r.Name FROM project_child__c WHERE Project__r.Id = '{!Project__c.Id}'");
var records = query.getArray("records");
var CreateRecords=[];

if(records[0] == null) {alert("No project child");}
for(var i = 0; i < records.length; i++)
{var PC = new sforce.SObject("Project_child__c");
PC.RecordType = records[i].RecordType.Id;
PC.Employee__c = records[i].Employee__r.Name;
CreateRecords.push(PC);}
result=sforce.connection.create([CreateRecords]);

What is the issue here?

Regards
Robert
Balaji Chowdary GarapatiBalaji Chowdary Garapati
@Robert Zentgraf:
Try changning the statement
PC.RecordType = records[i].RecordType.Id;
to
PC.recordtypeid= records[i].RecordType.Id;


Thanks,
Balaji
Robert ZentgrafRobert Zentgraf
Hi Balaji,

thx for your reply. I tried this, but I received the same error message :(

Regards
Robert