Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

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

https://login.salesforce.com/help/doc/en/overview_of_custom_object_relationships.htm

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.

Eg

Database.delete([select Id from contact where AccountId in :accIds]);
share|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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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