Activity Forums Salesforce® Discussions How to remove duplicate records in Salesforce?

  • krati

    Member
    April 6, 2020 at 4:41 pm

    Please elaborate if you want to remove duplicate records from a standard object's field or something else. In Case of prior one you can remove those from anonymous window.
    For Example:
    List<Account> listOfAccounts = [Select Id, name From Account limit 200];
    Set<String> accountSet = new Set<String>();
    List<Account> listOfDuplicateNames = new List<Account>();
    for(Account acc : listOfAccounts){
    if(accountSet.contains(acc.name)){
    listOfDuplicateNames.add(acc);
    }
    else {
    accountSet.add(acc.name);
    }
    }
    delete listOfDuplicateNames;

  • Shubham

    Member
    April 6, 2020 at 5:27 pm

    hi shweta,
    you can always use set collection, to remove duplicate records as per your requirement

  • Pooja

    Member
    April 6, 2020 at 5:52 pm

    By using set collection you can remove duplicate records in Salesforce.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos