You need to sign in to do that
Don't have an account?
Srikanth Dorepalli
how to add a custom object to another custom object (the related record) by setting Id field in salesforce when using dml
LOOK AT THIS ONE:-
Account acct = new Account(Name='SFDC Account');
insert acct;
// Once the account is inserted, the sObject will be
// populated with an ID.
// Get this ID.
ID acctID = acct.ID;
// Add a contact to this account.
Contact mario = new Contact(
FirstName='Mario',
LastName='Ruiz',
Phone='415.555.1212',
AccountId=acctID);
insert mario;
MY QUESTION:-
----------------------------
If i want to append the ID like above snippet for custom objects how can i achieve this
Account acct = new Account(Name='SFDC Account');
insert acct;
// Once the account is inserted, the sObject will be
// populated with an ID.
// Get this ID.
ID acctID = acct.ID;
// Add a contact to this account.
Contact mario = new Contact(
FirstName='Mario',
LastName='Ruiz',
Phone='415.555.1212',
AccountId=acctID);
insert mario;
MY QUESTION:-
----------------------------
If i want to append the ID like above snippet for custom objects how can i achieve this
I have just derived it from the Account - Contact relationship you have shown above.
Let me know if this helps.
All Answers
May I request you to please check the below link for Creating Parent and Child Records in a Single Statement Using Foreign Keys.
- https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_dml_foreign_keys.htm
I hope it will be helpful.BestRegards
RahulKumar
I have just derived it from the Account - Contact relationship you have shown above.
Let me know if this helps.