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
Siva PRSiva PR 

is it possible, when i have 2 objects(Parent and Child) and the relationship is "lookup", and how should i delete child records when after deleting Parent records?

Hargobind_SinghHargobind_Singh
You can go to field-properties, and define the behavior to delete this record if lookup record is deleted. Here is some info from Salesforce help. Link: 

https://help.salesforce.com/HTViewHelpDoc?id=overview_of_custom_object_relationships.htm&language=en_US (https://help.salesforce.com/HTViewHelpDoc?id=overview_of_custom_object_relationships.htm&language=en_US)

If the lookup field is optional, you can specify one of three behaviors to occur if the lookup record is deleted:
Clear the value of this field This is the default. Clearing the field is a good choice when the field does not have to contain a value from the associated lookup record.
Don’t allow deletion of the lookup record that’s part of a lookup relationship This option restricts the lookup record from being deleted if you have any dependencies, such as a workflow rule, built on the relationship.
Delete this record also Available only if a custom object contains the lookup relationship, not if it’s contained by a standard object. However, the lookup object can be either standard or custom. Choose when the lookup field and its associated record are tightly coupled and you want to completely delete related data. For example, say you have an expense report record with a lookup relationship to individual expense records. When you delete the report, you probably want to delete all of the expense records, too.
Warning
Choosing Delete this record also can result in a cascade-delete. A cascade-delete bypasses security and sharing settings, which means users can delete records when the target lookup record is deleted even if they don’t have access to the records. To prevent records from being accidentally deleted, cascade-delete is disabled by default. Contact Salesforce.com to get the cascade-delete option enabled for your organization.
Cascade-delete and its related options are not available for lookup relationships to business hours, community, lead, price book, product, or user objects.
Arunkumar RArunkumar R
Hi Siva,

By default it is not possible. But you can do via Trigger. Here is the sample code,

trigger DeleteContact on Account (after delete)
{
    List<Contact> contacts = [SELECT AccountId FROM Contact WHERE AccountId IN:Trigger.OldMap.keyset()];
    delete contacts;
}