public List<AggregateResult> acc{get;set;} acc=[SELECT Name, count(Id) FROM Account GROUP BY Name HAVING count(Id)>1]; for(AggregateResult ar : acc) { System.debug('duplicate name values'+ar); }
public class DuplicateAccNames { public List<Account> acc{get;set;} public void accMethod() { acc=[SELECT Name, count(Id) FROM Account GROUP BY Name HAVING count(Id)>1]; for(Account ac : acc) { System.debug('duplicate name values'+ac); } }
error in line 6 ille illegal assignment from List<aggraregate results> to list<account>
public List<AggregateResult> acc{get;set;} acc=[SELECT Name, count(Id) FROM Account GROUP BY Name HAVING count(Id)>1]; for(AggregateResult ar : acc) { System.debug('duplicate name values'+ar); }
This will give you the name of all Accounts that are duplicates:
List<AggregateREsult> lstAR = [SELECT Name, count(Id) FROM Account GROUP BY Name HAVING count(Id)>1]; for(AggregateResult a : lstAR) { system.debug('===================== ' + a.get('Name')); }
Refer this links :
http://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_SOQL_agg_fns.htm
http://blog.jeffdouglas.com/2010/04/12/using-aggregateresult-in-salesforce-com-soql/
public class DuplicateAccNames
{
public List<AggregateResult> acc{get;set;}
acc=[SELECT Name, count(Id) FROM Account GROUP BY Name HAVING count(Id)>1];
for(AggregateResult ar : acc)
{
System.debug('duplicate name values'+ar);
}
}
}
All Answers
hi ,
here my code.......................
public class DuplicateAccNames
{
public List<Account> acc{get;set;}
public void accMethod()
{
acc=[SELECT Name, count(Id) FROM Account GROUP BY Name HAVING count(Id)>1];
for(Account ac : acc)
{
System.debug('duplicate name values'+ac);
}
}
error in line 6 ille illegal assignment from List<aggraregate results> to list<account>
Refer this links :
http://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_SOQL_agg_fns.htm
http://blog.jeffdouglas.com/2010/04/12/using-aggregateresult-in-salesforce-com-soql/
public class DuplicateAccNames
{
public List<AggregateResult> acc{get;set;}
acc=[SELECT Name, count(Id) FROM Account GROUP BY Name HAVING count(Id)>1];
for(AggregateResult ar : acc)
{
System.debug('duplicate name values'+ar);
}
}
}
This will give you the name of all Accounts that are duplicates:
List<AggregateREsult> lstAR = [SELECT Name, count(Id) FROM Account GROUP BY Name HAVING count(Id)>1];
for(AggregateResult a : lstAR)
{
system.debug('===================== ' + a.get('Name'));
}