You need to sign in to do that
Don't have an account?
SFDC Admin 56
Before Insert or Upsert list must not have two identically equal elements()
Before Insert or Upsert list must not have two identically equal elements
When i am trying to update records from data loader, its giving me this error.Before Insert or Upsert list must not have two identically equal elements.
Below is my code and how can i change List to map?
trigger Sharingupdate on Account (after update)
{
Legal_Doc__Share PrimarysalesrepShr = new Legal_Doc__Share();{
if(trigger.isUpdate)
{
Set<Id> setAcc = new Set<Id>();
Set<String> setPrimSal= new Set<String>();
for (Account a : Trigger.old )
{
setAcc.add(a.id);
setPrimSal.add(a.Primary_Sales_Rep2__c);
}
List<Legal_Doc__c> legaldocu = [Select id From Legal_Doc__c where Accounts__c in : setAcc];
List<Legal_Doc__Share> legdoc = [Select UserOrGroupId From Legal_Doc__Share Where UserOrGroupId in :setPrimSal and ParentId = :legaldocu ];
if(legdoc!= null)
{
Delete legdoc;
}
}
List<Legal_Doc__Share> ListPrimarysalesrepShr = new List<Legal_Doc__Share>();
Set<ID> setAccId = new Set<Id>();
for (Account an : Trigger.new )
{
setAccId.add(an.id);
}
List<Legal_Doc__c> Listlegaldocum = [Select id,Accounts__c From Legal_Doc__c where Accounts__c in :setAccId];
Map<Id,Legal_Doc__c> mapAccWiseLegalIDoc = new Map<Id,Legal_Doc__c>();
for(Legal_Doc__c leg : Listlegaldocum)
{
mapAccWiseLegalIDoc.put(leg.Accounts__c,leg);
}
for (Account an : Trigger.new )
{
If(mapAccWiseLegalIDoc.containsKey(an.Id))
{
PrimarysalesrepShr.ParentId = mapAccWiseLegalIDoc.get(an.Id).Id;
PrimarysalesrepShr.UserOrGroupId = an.Primary_Sales_Rep2__c ;
PrimarysalesrepShr.AccessLevel = 'edit';
ListPrimarysalesrepShr.add(PrimarysalesrepShr);
}
}
if (PrimarysalesrepShr.UserOrGroupId!=null){
if(ListPrimarysalesrepShr.size() > 0 )
{
insert ListPrimarysalesrepShr ;
}
}
}
}
When i am trying to update records from data loader, its giving me this error.Before Insert or Upsert list must not have two identically equal elements.
Below is my code and how can i change List to map?
trigger Sharingupdate on Account (after update)
{
Legal_Doc__Share PrimarysalesrepShr = new Legal_Doc__Share();{
if(trigger.isUpdate)
{
Set<Id> setAcc = new Set<Id>();
Set<String> setPrimSal= new Set<String>();
for (Account a : Trigger.old )
{
setAcc.add(a.id);
setPrimSal.add(a.Primary_Sales_Rep2__c);
}
List<Legal_Doc__c> legaldocu = [Select id From Legal_Doc__c where Accounts__c in : setAcc];
List<Legal_Doc__Share> legdoc = [Select UserOrGroupId From Legal_Doc__Share Where UserOrGroupId in :setPrimSal and ParentId = :legaldocu ];
if(legdoc!= null)
{
Delete legdoc;
}
}
List<Legal_Doc__Share> ListPrimarysalesrepShr = new List<Legal_Doc__Share>();
Set<ID> setAccId = new Set<Id>();
for (Account an : Trigger.new )
{
setAccId.add(an.id);
}
List<Legal_Doc__c> Listlegaldocum = [Select id,Accounts__c From Legal_Doc__c where Accounts__c in :setAccId];
Map<Id,Legal_Doc__c> mapAccWiseLegalIDoc = new Map<Id,Legal_Doc__c>();
for(Legal_Doc__c leg : Listlegaldocum)
{
mapAccWiseLegalIDoc.put(leg.Accounts__c,leg);
}
for (Account an : Trigger.new )
{
If(mapAccWiseLegalIDoc.containsKey(an.Id))
{
PrimarysalesrepShr.ParentId = mapAccWiseLegalIDoc.get(an.Id).Id;
PrimarysalesrepShr.UserOrGroupId = an.Primary_Sales_Rep2__c ;
PrimarysalesrepShr.AccessLevel = 'edit';
ListPrimarysalesrepShr.add(PrimarysalesrepShr);
}
}
if (PrimarysalesrepShr.UserOrGroupId!=null){
if(ListPrimarysalesrepShr.size() > 0 )
{
insert ListPrimarysalesrepShr ;
}
}
}
}
List<Legal_Doc__Share> ListPrimarysalesrepShr = new List<Legal_Doc__Share>();
insert ListPrimarysalesrepShr