You need to sign in to do that
Don't have an account?
kondru sampreeth
i got an error "line No 5 expecting a right parentheses, found ';'--- trigger line No 12 same error in class, how to resolve this
please need your help
line No 5 expecting a right parentheses, found ';'--- trigger
line No 12 same error in class
--------------------------------------------------------------
trigger FindDupesonLead on Lead (before insert) {
for (Lead myLead : Trigger.new) {
if (myLead.Email != null) {
List<contact> dupes = [SELECT Id FROM Contact WHERE Email = :myLead.Email];
//below line getting an error
if (dupes != null && dupes.size() > 0) {
String errorMessage = 'Duplicate contact found! ';
errorMessage += 'Record ID is ' + dupes[0].Id;
myLead.addError(errorMessage);
}
}
}
}
---------------------------------------------------------
public class FindDupesonLead {
public static List<account> mergeDupeContactsInAnAccount(List<account> accList) {
// Create a set of duplicate contacts that
// we will delete later. We use a set because it has the contains() method
Set<contact> duplicates = new Set<contact>();
// For each account, we will loop over every contact to find a dupe
for (Account a : accList) {
//below line i am getting an error
// There needs to be at least 2 contacts to have a dupe
if (a.Contacts != null & a.Contacts.size() > 1) {
// Iterate across the account's contacts to find dupes
for (Contact outerContact : a.Contacts) {
// Skip this contact if it has been identified as a dupe
if (duplicates.contains(outerContact)) { continue; }
// Iterate again though the contacts to find a match by email or name
for (Contact innerContact : a.Contacts) {
// Skip this contact if it has been identified as a dupe
if (duplicates.contains(innerContact )) { continue; }
// Since the original contact is in this list, make sure we don't match it
if (outerContact.Id != innerContact.Id) {
// Check for a match by email
if (outerContact.Email != null && outerContact.Email.equals(innerContact.Email)) {
duplicates.add(innerContact);
continue;
}
// Now check for a match by name
if (outerContact.FirstName != null && innerContact.FirstName != null) {
String outerContactName = outerContact.FirstName + outerContact.LastName;
String innerContactName = innerContact.FirstName + innerContact.LastName;
if (outerContactName.equals(innerContactName)) {
duplicates.add(innerContact);
continue;
}
}
}
}
}
}
}
// Delete dupes
// if (duplicates.size() > 0) {
// List<contact> duplicatesList = new List<contact>();
// duplicatesList.addAll(duplicates);
// delete duplicatesList;
}
return accList;
}
}
line No 5 expecting a right parentheses, found ';'--- trigger
line No 12 same error in class
--------------------------------------------------------------
trigger FindDupesonLead on Lead (before insert) {
for (Lead myLead : Trigger.new) {
if (myLead.Email != null) {
List<contact> dupes = [SELECT Id FROM Contact WHERE Email = :myLead.Email];
//below line getting an error
if (dupes != null && dupes.size() > 0) {
String errorMessage = 'Duplicate contact found! ';
errorMessage += 'Record ID is ' + dupes[0].Id;
myLead.addError(errorMessage);
}
}
}
}
---------------------------------------------------------
public class FindDupesonLead {
public static List<account> mergeDupeContactsInAnAccount(List<account> accList) {
// Create a set of duplicate contacts that
// we will delete later. We use a set because it has the contains() method
Set<contact> duplicates = new Set<contact>();
// For each account, we will loop over every contact to find a dupe
for (Account a : accList) {
//below line i am getting an error
// There needs to be at least 2 contacts to have a dupe
if (a.Contacts != null & a.Contacts.size() > 1) {
// Iterate across the account's contacts to find dupes
for (Contact outerContact : a.Contacts) {
// Skip this contact if it has been identified as a dupe
if (duplicates.contains(outerContact)) { continue; }
// Iterate again though the contacts to find a match by email or name
for (Contact innerContact : a.Contacts) {
// Skip this contact if it has been identified as a dupe
if (duplicates.contains(innerContact )) { continue; }
// Since the original contact is in this list, make sure we don't match it
if (outerContact.Id != innerContact.Id) {
// Check for a match by email
if (outerContact.Email != null && outerContact.Email.equals(innerContact.Email)) {
duplicates.add(innerContact);
continue;
}
// Now check for a match by name
if (outerContact.FirstName != null && innerContact.FirstName != null) {
String outerContactName = outerContact.FirstName + outerContact.LastName;
String innerContactName = innerContact.FirstName + innerContact.LastName;
if (outerContactName.equals(innerContactName)) {
duplicates.add(innerContact);
continue;
}
}
}
}
}
}
}
// Delete dupes
// if (duplicates.size() > 0) {
// List<contact> duplicatesList = new List<contact>();
// duplicatesList.addAll(duplicates);
// delete duplicatesList;
}
return accList;
}
}
Please Try following code for trigger
Thanks,
Himanshu
Salesforce Certified Developer | Administrator | Service Cloud Consultant
P.S. If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.