I have two fields in my Opportunity object: Phone_1__c & Phone_2__c. Now I have to check to check the whole Org, if there are any opportunities made earlier using any of these two numbers. (Org has more than 53k records).
I added the
Phone_2__c to the list and performed SOQL using that
[SELECT count() FROM Opportunity WHERE (Phone_1__c IN :oppAddOnPhoneList OR Phone_2__c IN :oppAddOnPhoneList)
oppAddOnPhoneList : list containing Phone numbers of all current Opportunities.
Now the problem is, this code works fine for single opportunity. It will not work for a
list<Opportunities> containing new phone number and existing phone number, as the
oppAddOnPhoneList always has some existing phone number present.
Any suggestions /ideas to bulkify this code?
Note: I will also add other filters in SOQL ( Stage, createddate etc..,) Batch apex will run asynchronously. But I need to throw the error instantly. Read about the @readOnly annotation. But does it need vf page?