I have a few simple (and a bit hacky) apex scripts that i use to count /clean up duplicate leads. I haven't used them or my dev environment in about a year, and trying to execute them now triggers compile errors. Nothing has changed in the scripts since they worked. I can't see anything wrong. Please help.
I am running Eclipse Version: Mars.2 Release (4.5.2) and Force.com IDE plugin version 36.0.0.
Using the below script as an example, executing autonomously triggers the following error: Compile error at line 35 column 5 Unexpected token '<'.
IF i create a new Apex class file and paste the scrip in there, i get this completely different syntax error: Unexpected token 'list' at line 8
Here's my script:
/*
Delete Duplicate FXWare Leads based on email
*/
//Get a list of all leads that have duplicate email addresses.
// Include all leads
list<AggregateResult> dupLeads = [Select count(id) numDupLeads, email from Lead where isConverted = false and recordTypeId = '012A0000000xnhD' group by email having count(id) > 1];
// Include only Open leads
//list<AggregateResult> dupLeads = [Select count(id) numDupLeads, email from Lead where isConverted = false and recordTypeId = '012A0000000xnhD' and Status = 'Open' group by email having count(id) > 1];
// list for storing the email addresses of duplicate leads
list<string> dupLeadEmails = new list<string>();
//loop through the results and add the email to a list so we can find them again
for(AggregateResult ar : dupLeads)
{
dupLeadEmails.add(string.valueOf(ar.get('email')));
}
/*
Get Ids of all duplicate leads, order by email then created date or last modified date,
depending on which line is commented.
*/
// Created Date ASC. Choose this to keep the first lead created.
//list<Lead> listLeads = [select id, email from Lead where email in :dupLeadEmails and recordTypeId = '012A0000000xnhD' and isConverted = false order by email, createdDate ASC ];
//Last Modified date DSC. Choose this to keep the recently edited lead
list<Lead> listLeads = [select id, email from Lead where email in :dupLeadEmails and recordTypeId = '012A0000000xnhD' and isConverted = false order by email, LastModifiedDate DSC ];
//List of leads that will be deleted
list<Lead> leadsToDelete = new list<Lead>();
//Store the last email looked at
string lastLeadEmail = 'placeholder12345';
for(Lead l : listLeads)
{
if(l.email == lastLeadEmail)
{
leadsToDelete.add(l);
}
//set the variable for the next iteration
lastLeadEmail = l.email;
}
if(!leadsToDelete.isEmpty())
{
//delete those suckers.
System.debug('Number of Duplicates: ' + leadsToDelete.size());
//delete leadsToDelete;
}
else
{
System.debug('Nothing to Do!!!!!!');
}