Blog

Blog » 2017 » February » 14 » Delete chain
21:24
Delete chain

OLI: 

Select Id, Bill_to_Email__c FROM Order_Lines__c 
WHERE Order__r.Bill_To_Brand_Contact__r.System_delete__c = true

 

Order:

Select Id, Bill_To_Brand_Contact__r.System_delete__c 
FROM Order where Bill_To_Brand_Contact__r.System_delete__c = true

 

Cases

Select Id FROM Case WHERE Contact.System_delete__c = true

Contact:

Select Id FROM Contact where System_delete__c = true

 

Outdated orders of non CMs

Select Id, eWinery_Order_Date__c FROM Order_Lines__c 
WHERE Order__r.Bill_To_Brand_Contact__r.Has_being_a_club_member__c = false 
AND Order__r.eWinery_Date_Completed__c < LAST_N_YEARS:5

***

list<order_lines__c> oli= [Select Id FROM Order_Lines__c 
WHERE Order__r.Bill_To_Brand_Contact__r.System_delete__c = true];
database.delete(oli,false);

list<order> o= [Select Id FROM Order where Bill_To_Brand_Contact__r.System_delete__c = true];
database.delete(o,false);

list<contact> c= [Select Id FROM Contact where System_delete__c = true];
database.delete(c,false);

list<account> a= [select Id,name from Account where Id not In (select AccountId from Contact)];
database.delete(a,false);