You need to sign in to do that
Don't have an account?
Yogesh Biyani
SOQL help (find contacts with emails with numbers before the @ )
Here are some examples of fake contacts in our database which we would like to clean.
function readOnly(count){ }
You need to sign in to do that
Don't have an account?
global class ContactsDelBatch implements Database.Batchable<sObject>
{
global Database.QueryLocator start(Database.BatchableContext BC)
{
String query = 'SELECT Id,Name,email from Contact';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<Contact> contacts)
{
List<Contact> contactListToDelete = new List<Contact>();
for ( Contact c : contacts)
{
String[] tempStrings = c.email.split('@');
if(tempStrings[0].isNumeric()){
contactListToDelete.add(c);
}
}
if(contactListToDelete.size()>0){
delete contactListToDelete;
}
}
global void finish(Database.BatchableContext BC)
{
}
}
Save this class and run from anonymous class
Id batchJobId = Database.executeBatch(new ContactsDelBatch(), 200);
Thanks for the detailed reply and I sure this will be useful. However, I was thinking of using SOQL because I want to manually check in the developer console before deleting the same.
Yogesh
Create a formula field Is_Number_Email__c = ISNUMBER(LEFT(Email,Find("@", Email)-1))
Use the formula field to filter the results
SELECT Id,Name,Email,Is_Number_Email__c from Contact where Is_Number_Email__c=true