You need to sign in to do that
Don't have an account?
RAJU_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
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.