You need to sign in to do that
Don't have an account?
Errors in trigger for preventing duplicate leads in Cookbook
Error: Compile Error: expecting a right parentheses, found 'get' at line 10 column 1 |
|
Error: Compile Error: Method does not exist or incorrect signature: [MAP:Id,SOBJECT:Lead].(Id) at line 9 column 16
I am not sure I know what is causing this error or how to fix. Any thoughts??
Here is the trigger from the cookbook:
trigger leadDuplicatePreventer on Lead (before insert, before update) {
Map<String, Lead> leadMap=new Map<String, Lead>();
for (Lead lead : System.Trigger.New) {
//make sure we don't treat an email address that
// isn't changing during an update as a duplicate.
if ((lead.Email !=null) &&
(System.Trigger.isInsert ||
(lead.Email != System.Trigger.oldMap.
get(lead.Id).Email))) {
//make sure another new lead isn't also a duplicate
if (leadMap.containsKey(lead.Email)) {
lead.Email.addError('Another new lead has the '
+'same email address.');
}else {
leadMap.put(lead.Email, lead);
}
}
}
//Using a single database query, find all the leads in
//the database that have the same email address as any
// of the leads being inserted or updated.
for (Lead lead : [SELECT email FROM Lead
WHERE Email IN :leadMap.KeySet ()]) {
Lead newLead=leadMap.get(lead.Email);
newLead.Email.addError('A lead with this email '
+ 'address already exists.');
}
}
System.Trigger.oldMap.get(lead.Id).Email should go on the same line, but it appears to be a new line as it's printed in the cookbook :smileyvery-happy:
The following code is working for me:
I am playing with this, it works in my developer account, then I tried to deploy it into my production. I followed the instructions on the apex programmer guide(installed SDK, ANT, MIGRATION TOOL), but I cannot deploy it.
error msg:
Code coverage issue, class: leadDuplicatePreventer -- test coverage of selected Apex Trigger is 0%, at least 1% test coverage is required
Code coverage issue -- Average test coverage across all apex classes and triggers is 0%, at least 75% test coverage is required
replace
System.assert(e.getDmlFields(0)[0] == 'Email');
with
System.assert(e.getDmlFields(0)[0] == Lead.Email);
you will need to replace all lines where error is occuring..
Cheers!
Sree