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
AK123AK123 

Creating record on child object

Hello, I am trying to create a custom button that will create a child object record from a parent object.  I am trying to create a button that will create a new CHILD record, off of a custom button found on the PARENT record list view. PARENT__c and CHILD__c are both custom objects, master-detail relationship.  Below is the code i compiled, but am having no luck. Any assistance would be greatly appreaciated.

 

{!REQUIRESCRIPT("/soap/ajax/13.0/connection.js")}

var records = {!GETRECORDIDS( $ObjectType.PARENT__C)};
var UpdateID = '{!PARENT__C.Id}';
var c= new sforce.SObject("CHILD__C");
c.PARENT__C = UpdateID;
c.Name = new Date ();
c.Details__c = 'No New Update';
var result = sforce.connection.create(records);
window.location.reload();

if (result[0].success=='false') {
alert(result[0].errors.message);
} else {
location.reload(true);
}

 

THANKS