You need to sign in to do that
Don't have an account?

System.DmlException: Insert failed. First exception on row 1; first error: UNKNOWN_EXCEPTION, Use one of these records?: []
Hi,
I have a legacy code and giving error at below highlighted line 146. Do you see any issue in code?
Basically it needs to create contacts from the email received by Salesforce. In Email attachement we are sending list of contacts that needs to be create. I am not sure why it’s giving error sometimes.
//loop through the good list to create the contacts
Integer points = 0;
for (csvLineWrapper lw : okToProcess) {
//Savepoint sp = Database.setSavepoint();
//Boolean contactOk = true;
//Boolean isNewContact = false;
//Boolean isExistingContact = false;
Contact c = emailToContactMap.get(lw.ownerEmailAddress);
if (c == null) {
c = emailToExistingContactMap.get(lw.ownerEmailAddress);
if (c == null) {
c = new Contact(AccountId = petFirstAcct.Id, LastName = lw.ownerLastName, FirstName = lw.ownerFirstName, MailingPostalCode = lw.ownerPostalCode,
Phone = lw.ownerPhone, Email = lw.ownerEmailAddress, RecordTypeId = petOwnerRecType.Id, Breeder__c = senderContact.AccountId,
Language__c = senderContact.Account.Language__c, Date_Joined__c = lw.joinedDate);
//insert c;
//isNewContact = true;
emailToContactMap.put(lw.ownerEmailAddress, c);
} else {
//emailToContactMap.put(lw.ownerEmailAddress, c);
//isExistingContact = true;
lw.infoMsg = 'line: ' + lw.lineNo + ': contact ' + lw.ownerFirstName + ' ' + lw.ownerLastName + ' already exists.';
}
}
}
insert emailToContactMap.values();
I have a legacy code and giving error at below highlighted line 146. Do you see any issue in code?
Basically it needs to create contacts from the email received by Salesforce. In Email attachement we are sending list of contacts that needs to be create. I am not sure why it’s giving error sometimes.
//loop through the good list to create the contacts
Integer points = 0;
for (csvLineWrapper lw : okToProcess) {
//Savepoint sp = Database.setSavepoint();
//Boolean contactOk = true;
//Boolean isNewContact = false;
//Boolean isExistingContact = false;
Contact c = emailToContactMap.get(lw.ownerEmailAddress);
if (c == null) {
c = emailToExistingContactMap.get(lw.ownerEmailAddress);
if (c == null) {
c = new Contact(AccountId = petFirstAcct.Id, LastName = lw.ownerLastName, FirstName = lw.ownerFirstName, MailingPostalCode = lw.ownerPostalCode,
Phone = lw.ownerPhone, Email = lw.ownerEmailAddress, RecordTypeId = petOwnerRecType.Id, Breeder__c = senderContact.AccountId,
Language__c = senderContact.Account.Language__c, Date_Joined__c = lw.joinedDate);
//insert c;
//isNewContact = true;
emailToContactMap.put(lw.ownerEmailAddress, c);
} else {
//emailToContactMap.put(lw.ownerEmailAddress, c);
//isExistingContact = true;
lw.infoMsg = 'line: ' + lw.lineNo + ': contact ' + lw.ownerFirstName + ' ' + lw.ownerLastName + ' already exists.';
}
}
}
insert emailToContactMap.values();
Please use below code:-
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
Hi Himanshu
I think you have to use
database.inser(emailToContactMap.values(),false); in place of insert emailToContactMap.values();
If you find your Solution then mark this as the best answer.
Thank you!
Regards,
Suraj Tripathi