title: Salesforce apex code creates duplicates in custom object
body: <p>I have this apex batch class:
  The MDU_Squad_Data_min__c custom object below has a lot of duplicate values in the city &amp; province column. 
  With the below code I was able to get rid of duplicates with the help of the contains method to a certain extent, but still there are duplicate values:</p>
  
  <pre><code>global void execute(Database.BatchableContext BC, List&lt;MDU_Squad_Data_min__c&gt; cities) {                  
          List&lt;sumchans__City_Master__c&gt; cityList = new List&lt;sumchans__City_Master__c&gt;(); 
          List&lt;String&gt; cityProvinceList = new List&lt;String&gt;();
          for(MDU_Squad_Data_min__c c: cities) { 
              String cityprovince; 
              cityprovince = (c.CITY_NAME__c).trim() + (c.PROVINCE_CODE__c).trim();                                           
              if(!cityProvinceList.contains(cityprovince)) { 
  
                  sumchans__City_Master__c city = new sumchans__City_Master__c();
                  city.Name = c.CITY_NAME__c;
                  city.sumchans__PROVINCE__c = c.PROVINCE_CODE__c; 
                  cityList.add(city);
              }
              cityProvinceList.add(cityprovince);
          }        
          Database.SaveResult[] MySaveResult = Database.Insert(cityList, false);
  </code></pre>
  
  <p>Also attaching the results:
  <a href="https://i.stack.imgur.com/mKEw9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mKEw9.png" alt="enter image description here"></a></p>