function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SNSNSNSN 

How to delete all records except one from Child Object for each Parent Object record?

Hi,

 

I have requirement where we have to delete all the records except one from a child object for each Parent object. 

 

Example : Parent object : A

                   Child Object : B

 

'A' object has 1 to many relation with 'B' Object.

For each 'A' record we have to delete all the related records except one from Object 'B' . The exception record can be any record in the child object. 

Can somebody help me with SOQL query for this? 

 

Thanks in Advance,

SNSN

fredkafredka

This might not be what you are looking for but this is what I would do... I would export the data to microsoft access to manipulate..  I would add a field in access to mark all those that should be deleted using a query... then use the apex data loaded to delete....

 

Fred

SNSNSNSN

Thank you very much for the reply!!