I have two objects with a master-detail relation ship. Invoice and Invoice Lines.

I am basically syncing this up from an external program into Salesforce. During updates, a lot of changes may be made including deleting certain lines on the source system.

So I thought its better that I delete all the Invoice lines first and then recreate them.

At this point I have the parent's(Invoice) ID, is it possible to delete all child records of this record without fetching their IDs?

I would also need to delete all the attachment records. It will be great if someone can give me a few pointers here.

I am hoping to avoid querying for the Invoice lines and attachments for every Invoice.

Thank you. Wish you all a happy new year.


When a master record is deleted, the related detail and subdetail records are also deleted.


So if you deleted the parent records, you wouldn't need to do anything explicitly to delete the child records.

The ids of the the records to be deleted need to be specified explicitly (unless M/D) - you'd therefore need to query for the child record ids before deleting them.


Database.delete([select Id from contact where AccountId in :accIds]);
| improve this answer | |
  • I was hoping not to delete the parent every time there is a change. Just the child records. – Richard N Jan 1 '13 at 16:15
  • Added response to answer. You will need to query for ids. – techtrekker Jan 2 '13 at 8:16
  • Yes I figured this out yesterday. So delete() does require the ids of the records being deleted and I am querying to obtain them first. I wish we could do this in just one query like "delete from" in SQL. But i guess SF have their reasons. Thanks for replying. Marking as answer. – Richard N Jan 2 '13 at 16:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.