I have two junction objects, say A and B, between User and Account. Now my scenario is that, when a record of A between User U1 and Account A1 - is deleted -> then I need to clear the user field having value U1 in object B records under the same account A1.
So in the bulkified implementation of this logic in a trigger, I have to consider the whole trigger.old( 200 records) and hence do the query in such a way
SELECT .. FROM B__c WHERE Account__c in Set1 AND User__c in Set2
Now this could possibly bring many unwanted records i.e. B records under A1 but under a different user say U2 that was a parent in another deleted A record. So my question is how to make this query more selective, such that I only want matching pairs of AccountID and UserID i.e. I only want B records in A1+U1 , A2+U2 etc occur. Hope I was clear.
An idea that came to my mind( haven't done feasibility check), create a formula field on object B, that contains the concatenated vlues of AccountID + UserID of that B record. Then use the WHERE clause as
SELECT ... FROM B__c WHERE IDConCat_Field__c IN SetWith IDConcatValues
I was hoping to actually implement this solution completely using apex and SOQL, Any ideas? Thanks in advance