function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Phani PYDIMARRY 11Phani PYDIMARRY 11 

SOQL Query to extract same name ,INDUSTRY records or duplicate records

Hello, 
I have a unique name which is a number in string format and tracking_code on an object and I there are other duplicate records too with the same combination. I would want to find the records with the same combination to use them somewhere else. Please see my code and let me know if I am doing it right.
List<Account> inaccts = [select ID, name, tracking_code__c from Account where flag__c = false];
map<string, ID> inactiveRecs = new map<string, ID>();
for(Account acc:inaccts ){
inactiveRecs.put(acc.name, acc.code__C);
}

// I am creating this list to extract exact combination of name and tracking_code for records whose flag is true
list<Account> actAccs = [select ID, name, tracking_code__c from Account where flag__c = true AND name in: inactiveRecs.keyset() AND tracking_code__c in inactiveRecs.values() ];

 
SUCHARITA MONDALSUCHARITA MONDAL

Hi Phani,

I guess you are checking Account with Same Name and  SameTracking Code . 
Just add check for null pointer  for lists as -->  inaccts.size() > 0
Add colon for 'tracking_code__c in inactiveRecs.values()' 

Thanks,
Sucharita