function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jerome MaddenJerome Madden 

I'm getting the following error message when I attempt to create a new account with an existing (duplicate address).

Jerome MaddenJerome Madden
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger SpawnDefaultLocation caused an unexpected exception, contact your administrator: SpawnDefaultLocation: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: UNKNOWN_EXCEPTION, You're creating a duplicate record. We recommend you use an existing record instead.: []: Trigger.SpawnDefaultLocation: line 30, column 1


 
Jerome MaddenJerome Madden
User-added image
Jayant JadhavJayant Jadhav
Hi Jerome,

Can you plz post the code, screen shot is not clear to see the code.
Jerome MaddenJerome Madden
I couldn't cut and paste it, but here's a closer screen capture.
Jayant JadhavJayant Jadhav
@Jerome,

Plz check if there is any trigger or validation rule on Location objects.
Jerome MaddenJerome Madden
Set Location Details? If so, then it’s… 1 2 3 4 5 trigger SetLocationDetails on Location__c (before insert, before update) { for (Location__c l : Trigger.new) { l.Name = l.LocationName__c; } }
Jayant JadhavJayant Jadhav
@Jerome,
 
As per you code @ line 30 you are trying to insert locations(which is list of location__c object). And this is the line your are receiving the exception. So this indicates that the trigger on location object is throwing exception.

You have to post all the location__c objects triggers with before insert or after insert triggers. That will help us to find out this issue.

SetLocationDetails trigger looks good. Also plz check that if you have created any unique field on location object.


 
Jerome MaddenJerome Madden
Sorry, I’m just an executive. Not an IT guy. When I look at the list of the triggers the only things I see that are related to or mention locations are spawnlocation and the setlocationdetails. Where would I find location__c objects triggers with before insert or after insert triggers? And how would I know if we’ve got a unique field on the location object?
Jayant JadhavJayant Jadhav
OK,

To find out trigger by using below steps.
  1. GoTo--> Develop --> Apex Triggers (It will display all the trigger in system)
  2. Click on Sobject Type (column headers). This will sort all the triggers based on object.
  3. Look for Location__c rows. If you have multiple row it means this object contains multiple triggers.
  4. Click on each link and check whether it is implemented with after insert or before insert event. Ex 
    trigger SetLocationDetails on Location__c (before insert, before update)
To find out unique field in location object.
  1. GoTo--> Create--> objects --> location__c (click on link this will display page with fields in location object)
  2. check fields with data type column as Unique. Ex: Email (Unique)
Jerome MaddenJerome Madden
Thanks! See below: in red