You need to sign in to do that
Don't have an account?
![Mohammad Hussain 7 Mohammad Hussain 7](https://dfc-org-production.my.site.com/img/userprofile/default_profile_45_v2.png)
Insert master and detail records in a single insert statement for custom objects
I am trying to insert master and detail records in a single insert statement. As a reference i took this example. https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_dml_foreign_keys.htm
When i excute the example provided here in my dev org it works. But, when i implement the same using custom objects not able to compile the class.
newOpportunity.Account = accountReference; //I get error in this line for custom objects
If I am using custom objects how can i make this line work? I was thinking this should be parent id but, it is not it gives illigal assignment error.
When i excute the example provided here in my dev org it works. But, when i implement the same using custom objects not able to compile the class.
newOpportunity.Account = accountReference; //I get error in this line for custom objects
If I am using custom objects how can i make this line work? I was thinking this should be parent id but, it is not it gives illigal assignment error.
You can insert like this
![Mohammad Hussain 7 Mohammad Hussain 7](https://dfc-org-production.my.site.com/img/userprofile/default_profile_45_v2.png)
Thanks for the quick response. This will work but, I dont want to insert parent first and then insert child. Also, i wanted to use external id to relate parent and child records as showen in the example. https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_dml_foreign_keys.htm