Last active
February 12, 2018 17:13
-
-
Save waltonzt/5e12e47713d7521eb0d4c5143519a25a to your computer and use it in GitHub Desktop.
Delete all contacts that arent tied to PO, SO, RO, RFQ, CQ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<Contact> cont = new List<Contact>(); | |
Map<String, inscor__Customer_Quote__c> cqMap = new Map<String, inscor__Customer_Quote__c>(); | |
Map<String, inscor__Sales_Order__c> soMap = new Map<String, inscor__Sales_Order__c>(); | |
Map<String, inscor__RFQ__c> rfqMap = new Map<String, inscor__RFQ__c>(); | |
Map<String, inscor__Purchase_Order__c> poMap = new Map<String, inscor__Purchase_Order__c>(); | |
Map<String, inscor__Repair_Order__c> roMap = new Map<String, inscor__Repair_Order__c>(); | |
for (inscor__Customer_Quote__c cq : [SELECT Id, inscor__Contact__c FROM inscor__Customer_Quote__c]) { | |
cqMap.put(cq.inscor__Contact__c, cq); | |
} | |
for (inscor__Sales_Order__c so : [SELECT Id, inscor__Contact__c FROM inscor__Sales_Order__c]) { | |
soMap.put(so.inscor__Contact__c, so); | |
} | |
for (inscor__RFQ__c rfq : [SELECT Id, inscor__Contact__c FROM inscor__RFQ__c]) { | |
rfqMap.put(rfq.inscor__Contact__c, rfq); | |
} | |
for (inscor__Purchase_Order__c po : [SELECT Id, inscor__Contact__c FROM inscor__Purchase_Order__c]) { | |
poMap.put(po.inscor__Contact__c, po); | |
} | |
for (inscor__Repair_Order__c ro : [SELECT Id, inscor__Contact__c FROM inscor__Repair_Order__c]) { | |
roMap.put(ro.inscor__Contact__c, ro); | |
} | |
for (Contact c : [SELECT Id FROM Contact WHERE inscor__External_Reference_ID__c = null]) { | |
if (!cqMap.containsKey(c.Id) && !soMap.containsKey(c.Id) && !rfqMap.containsKey(c.Id) && | |
!poMap.containsKey(c.Id) && !roMap.containsKey(c.Id)) { | |
cont.add(c); | |
} | |
} | |
delete cont; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment