Blog

Blog » 2016 » August » 9 » Select SOQL queries
20:06
Select SOQL queries

Cascade of deletion:

  1. order line items
  2. orders
  3. contacts
  4. accounts

Accounts

Accounts no Contacts
select Id,name from Account where Id not In (select AccountId from Contact)

or

list<Account> s= [select Id,name from Account 
                  where 
                  Id not In (select AccountId from Contact)
                  AND Id not In (select AccountId from Case)
                  AND Id!='001E000000CaEySIAV' AND ID!='001E000001dOqGbIAK'
                  LIMIT 200];
delete s;

Contacts

Contacts (Basic filter)

Select Id FROM Contact WHERE ((LastName='.' OR FirstName = null) OR (Email LIKE '%noemail.com' AND Phone = null)) AND (Active_Club_Memberships__c = 0 AND InActive_Club_Memberships__c = 0)

 

Select all contacts without orders and no name

Select Id FROM Contact where Id NOT In (Select Bill_To_Brand_Contact__c FROM Order) AND (LastName="." OR FirstName=null)

Orders

Orders no line items - ! DO NOT USE IT: There are valid orders with no OLI (kit deleted after Wine Event)

Select Id FROM Order WHERE Id NOT In (Select Order__c FROM Order_Lines__c)

 

Orders of filtered contacts

Select Id FROM Order WHERE ((Bill_To_Brand_Contact__r.FirstName = null OR Bill_To_Brand_Contact__r.LastName = '.') OR (Bill_To_Email__c LIKE '%noemail.com' AND Bill_To_Brand_Contact__r.Phone = null)) AND isClubMember__c = false

 

Order line items

Order line items from filtered contacts

Select Id, Bill_to_Email__c, Bill_to_Last_Name__c, Bill_to_First_Name__c, Bill_to_Phone__c FROM Order_Lines__c WHERE ((Bill_to_First_Name__c = null OR Bill_to_Last_Name__c = '.') OR (Bill_To_Email__c LIKE '%noemail.com' AND Bill_to_Phone__c = null)) AND isClubMember__c = false