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
RAJU_DEEPRAJU_DEEP 

Single query to insert new record in two or more custom objects.

Hello,

            I am in a requirement to insert the new record in two or more custom objects and for this if I use different queries then it insert the new record easily but I want to write the single query instead of the different queries. Is there any way to achieve this functionality. The code which i tried is:

 

 

public void save() {
MotorOwner__c mo = new MotorOwner__c(
name = Name,
Address__c = add);
insert mo;

Bike__c c = new Bike__c(
name = Name,
CC__c = cC,
Make__c = make);

/*Bike__c c = new Bike__c(
name = Name,
CC__c = cC,
Make__c = make,
MotorOwner__r.name = Name);*/

insert c;
}

In the above code the different query works fine but the commented single query doesnt works. So I there any way to insert the records in the single query, guide me where I am going wrong. Any suggestion will be helpfull for me.

 

Thanks & Regards

Raju Deep

 

 

Ispita_NavatarIspita_Navatar

You cannot insert data in different object the way you have tried in the commented code. As are insewrting c which is type bike_C, how will it insert motorowner object too. Salesforce does not provide for such facility.

 

Did this answer your question? if so, please mark it solved.