I need to delete/unidentify all contacts that haven't had any activity in the system or that don't have any Cases, Opportunities, Tasks or other important information related to them. This is to follow EU law (GDPR) that s.
I'm trying to query the contacts that I need to delete with this code in a batch job:
List<Contact> conQuery = [ SELECT Id, Name FROM Contact WHERE NOT( Memberstatus__c = :AC_Utils.stagePayed OR npo02__MembershipEndDate__c >= :thirtySixMonthsAgo OR npo02__LastCloseDate__c >= :thirtySixMonthsAgo OR ElectedMember__c = TRUE OR Id IN (SELECT ContactId FROM Case) OR Id IN (SELECT npsp__Primary_Contact__c FROM Opportunity))];
But I'm getting this error when adding the joins to the query:
Error: Semi join sub-selects are only allowed at the top level WHERE expressions and not in nested WHERE expressions.
Does anyone have a alternative solution?