You need to sign in to do that
Don't have an account?
Ramana123
when I am inserting a Lead with the same email filed it has to throw an exception and count muse be incremented in already existed email Record
In Debug logs the count is incrementing but in the record the count is not incrementing
public class DuplicateLeadExceptionHelper {
public static void leadException(List<Lead> leadList){
integer count=0;
List<Lead> updateRecords = new List<Lead>();
Map<String,Lead> existingRecords = new Map<String,Lead>();
for (Lead rec : [select LastName,Email,DuplicateRecordsExceptionCount__c
from Lead]) {
existingRecords.put(rec.LastName,rec);
}
System.debug('//'+existingRecords.keyset());
for(Lead leadRec : leadList){
if(Trigger.isbefore && Trigger.isInsert){
if(existingRecords.containskey(leadRec.LastName)){
leadRec.addError('Error! Duplicate Email Field, already this LastName exists in Name');
Lead countrec= existingRecords.get(leadRec.LastName);
if(countrec.DuplicateRecordsExceptionCount__c==null)
countrec.DuplicateRecordsExceptionCount__c=1;
else
countrec.DuplicateRecordsExceptionCount__c=countrec.DuplicateRecordsExceptionCount__c+1;
updateRecords.add(countrec);
}
}
}
system.debug('///'+updateRecords);
update updateRecords;
}
}
public class DuplicateLeadExceptionHelper {
public static void leadException(List<Lead> leadList){
integer count=0;
List<Lead> updateRecords = new List<Lead>();
Map<String,Lead> existingRecords = new Map<String,Lead>();
for (Lead rec : [select LastName,Email,DuplicateRecordsExceptionCount__c
from Lead]) {
existingRecords.put(rec.LastName,rec);
}
System.debug('//'+existingRecords.keyset());
for(Lead leadRec : leadList){
if(Trigger.isbefore && Trigger.isInsert){
if(existingRecords.containskey(leadRec.LastName)){
leadRec.addError('Error! Duplicate Email Field, already this LastName exists in Name');
Lead countrec= existingRecords.get(leadRec.LastName);
if(countrec.DuplicateRecordsExceptionCount__c==null)
countrec.DuplicateRecordsExceptionCount__c=1;
else
countrec.DuplicateRecordsExceptionCount__c=countrec.DuplicateRecordsExceptionCount__c+1;
updateRecords.add(countrec);
}
}
}
system.debug('///'+updateRecords);
update updateRecords;
}
}
>> https://developer.salesforce.com/forums/ForumsMain?id=9062I000000DGre
I think this is another question regarding the same issue mentioned over in the above link as stated you won't be able to show an error and update the field on new record that is being inserted.
Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.
Thanks.