Monday, 17 October 2016

Trigger to Delete All child records when parent record is deleted.

Deleting all child records when parent record is deleted.

Code:

trigger TriggerTo_Delete_ChildRecords on Account (before delete) {
    
    //To store parent ids
    list<id> AccountIds=new list<id>();
    for(Account accountVar:trigger.old)
    {
        AccountIds.add(accountVar.id);
    }  
    //Collecting all child records related to Parent records
    list<contact> listOfContacts=[select id from Contact where accountid in :AccountIds];
    system.debug('listOfContacts'+listOfContacts);
    //deleting child records
    delete listOfContacts;
}

Friday, 14 October 2016

How to Delete all scheduled Jobs in one go


To delete All the scheduled jobs in one Go, need to follow few steps.

Step 1: Login to your org.

Step 2: Open Developer Console.

Step 3: Copy and Paste the below code.

Step 4: Execute the code.


Code:

List<CronTrigger> cronstodelete = [Select Id from CronTrigger Limit 100];
for(CronTrigger CT: cronstodelete){
    System.abortjob(CT.Id);      
}