From the below code, I am fetching list of records where i am getting duplicate id's..again i am passing the list to a set to avoid duplicates. Can anyone suggest a bestway to avoid duplicates in a list.
query string = select field1__c, field2__c From object1__c;
List<object1__c> obj = Database.Query(queryString);
system.debug('obj list has'+lst);
set<id> ps = new Set<id>();
for(object1__c o: obj ){
ps.add(o.Id);
System.debug('>>>>>>>>>>>>ps'+ ps);
}
any help is greatly appreciated.