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
abhinav gangradeabhinav gangrade 

How to filter in SOQL on count criteria ?

How to filter in SOQL on count criteria ?This Query give me info more than one review related list record on acocunt
SELECT Account_Name__c, count(id) FROM Review__c GROUP BY Account_Name__c HAVING Count(Account_Name__c) > 1

My question is how to ensure that duplicates are not part of below FOR query, please provide code or syntax to me.

for(Private_Account_Information__c reviewForVar : [select id , Account_Name__c , Subject__c, X20_Group__c, Current_Provider__c, DRAD__c, PVR__c, Service_Contract_Participation__c from Review__c where Account_Name__c!= null])
SaranshSaransh
For question 1:
 
list<AggregateResult> lst = [ SELECT Account_Name__c, count(id) FROM Review__c GROUP BY Account_Name__c HAVING Count(Account_Name__c) > 1];

for(AggregateResult ag: lst)
{
system.debug('*********'+ag.get('expr0')); 
}

For question 2:
 
Map<Id, Review__c> mapReview = Map<Id, Review__c>([select id , Account_Name__c , Subject__c, X20_Group__c, Current_Provider__c, DRAD__c, PVR__c, Service_Contract_Participation__c from Review__c&nbsp;where Account_Name__c!= null]);

for(Id accId : mapReview.keyset())
{
Review__c obj1 = mapReview.get(accId);
//your code goes here
}