Skip to main content
Post Closed as "Needs details or clarity" by Adrian Larson, Sebastian Kessel, Mohith Shrivastava, Boris Bachovski, superfell
improved formatting
Source Link
Mark Pond
  • 23.1k
  • 2
  • 60
  • 104

I have a list which contains duplicate entries.

List<Account> aList1=new List<Account>([select Id,Name from account where Name LIKE '%Falcon%']);
Map<String,Account> aMap=new Map<String,Account>();
for(Account a:aList1)
{
    aMap.put(a.Name,a); // remove duplicate if any
}

Now I have created a trigger on account object that prevents duplicates.

Now I want to compare all values in aMap with all records in aList2. If there are any duplicates they are removed.

List<Account> aList2=[select ID,Name from Account ORDER BY Name];
for(Account a:aList2)
{
   if(aMap.containsKey(a.Name))
       aMap.remove(a.Name);  removes duplicates from aList1
} 

Database.Insert(aMap.values(),false);

Database.Insert(aMap.values(),false); ButBut after the for Loop, aMap is empty.Please let me know.

I have a list which contains duplicate entries.

List<Account> aList1=new List<Account>([select Id,Name from account where Name LIKE '%Falcon%']);
Map<String,Account> aMap=new Map<String,Account>();
for(Account a:aList1)
{
    aMap.put(a.Name,a); // remove duplicate if any
}

Now I have created a trigger on account object that prevents duplicates.

Now I want to compare all values in aMap with all records in aList2. If there are any duplicates they are removed.

List<Account> aList2=[select ID,Name from Account ORDER BY Name];
for(Account a:aList2)
{
   if(aMap.containsKey(a.Name))
       aMap.remove(a.Name);  removes duplicates from aList1
}

Database.Insert(aMap.values(),false); But after the for Loop, aMap is empty.Please let me know.

I have a list which contains duplicate entries.

List<Account> aList1=new List<Account>([select Id,Name from account where Name LIKE '%Falcon%']);
Map<String,Account> aMap=new Map<String,Account>();
for(Account a:aList1)
{
    aMap.put(a.Name,a); // remove duplicate if any
}

Now I have created a trigger on account object that prevents duplicates.

Now I want to compare all values in aMap with all records in aList2. If there are any duplicates they are removed.

List<Account> aList2=[select ID,Name from Account ORDER BY Name];
for(Account a:aList2)
{
   if(aMap.containsKey(a.Name))
       aMap.remove(a.Name);  removes duplicates from aList1
} 

Database.Insert(aMap.values(),false);

But after the for Loop, aMap is empty.Please let me know.

added 58 characters in body
Source Link
Eric
  • 54.4k
  • 11
  • 104
  • 196

I have a list which contains duplicate entries. List aList1=new List([select Id,Name from account where Name LIKE '%Falcon%']); Map<String,Account> aMap=new Map<String,Account>(); for(Account a:aList1) { aMap.put(a.Name,a); // remove duplicate if any }

List<Account> aList1=new List<Account>([select Id,Name from account where Name LIKE '%Falcon%']);
Map<String,Account> aMap=new Map<String,Account>();
for(Account a:aList1)
{
    aMap.put(a.Name,a); // remove duplicate if any
}

Now I have created a trigger on account object that prevents duplicates.

Now I want to compare all values in aMap with all records in aList2. If there are any duplicates they are removed. List aList2=[select ID,Name from Account ORDER BY Name]; for(Account a:aList2) { if(aMap.containsKey(a.Name)) aMap.remove(a.Name); removes duplicates from aList1 } Database

List<Account> aList2=[select ID,Name from Account ORDER BY Name];
for(Account a:aList2)
{
   if(aMap.containsKey(a.Name))
       aMap.remove(a.Name);  removes duplicates from aList1
}

Database.Insert(aMap.values(),false); But after the for Loop, aMap is empty.Please let me know.

I have a list which contains duplicate entries. List aList1=new List([select Id,Name from account where Name LIKE '%Falcon%']); Map<String,Account> aMap=new Map<String,Account>(); for(Account a:aList1) { aMap.put(a.Name,a); // remove duplicate if any }

Now I have created a trigger on account object that prevents duplicates.

Now I want to compare all values in aMap with all records in aList2. If there are any duplicates they are removed. List aList2=[select ID,Name from Account ORDER BY Name]; for(Account a:aList2) { if(aMap.containsKey(a.Name)) aMap.remove(a.Name); removes duplicates from aList1 } Database.Insert(aMap.values(),false); But after the for Loop, aMap is empty.Please let me know.

I have a list which contains duplicate entries.

List<Account> aList1=new List<Account>([select Id,Name from account where Name LIKE '%Falcon%']);
Map<String,Account> aMap=new Map<String,Account>();
for(Account a:aList1)
{
    aMap.put(a.Name,a); // remove duplicate if any
}

Now I have created a trigger on account object that prevents duplicates.

Now I want to compare all values in aMap with all records in aList2. If there are any duplicates they are removed.

List<Account> aList2=[select ID,Name from Account ORDER BY Name];
for(Account a:aList2)
{
   if(aMap.containsKey(a.Name))
       aMap.remove(a.Name);  removes duplicates from aList1
}

Database.Insert(aMap.values(),false); But after the for Loop, aMap is empty.Please let me know.

Source Link

remove duplicates from Map

I have a list which contains duplicate entries. List aList1=new List([select Id,Name from account where Name LIKE '%Falcon%']); Map<String,Account> aMap=new Map<String,Account>(); for(Account a:aList1) { aMap.put(a.Name,a); // remove duplicate if any }

Now I have created a trigger on account object that prevents duplicates.

Now I want to compare all values in aMap with all records in aList2. If there are any duplicates they are removed. List aList2=[select ID,Name from Account ORDER BY Name]; for(Account a:aList2) { if(aMap.containsKey(a.Name)) aMap.remove(a.Name); removes duplicates from aList1 } Database.Insert(aMap.values(),false); But after the for Loop, aMap is empty.Please let me know.