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
saurabh sharmasaurabh sharma 

soql query to get records with same account name

I have to create a soql query on accounts object, to get the records with same account name.
ramlakhanramlakhan
https://developer.salesforce.com/forums/ForumsMain?id=906F000000091yLIAQ
Mani RenusMani Renus
Don't know why you asking this Qn
Anyway for your referance(As per my understanding of your Qn)

List<Account> lacc=new List<Account>();
lacc=[select id,name form Account where name='saurabh sharma'];

Hope it helps U
 
saurabh sharmasaurabh sharma
you have to write query for accounts with same name.
Mani RenusMani Renus
Sorry i'm not getting your ponit. Can you brief it more
saurabh sharmasaurabh sharma
we have to count records with same account name.
PuneetsfdcPuneetsfdc
You dont have to do anything, use GROUP BY with HAVING, try below code to get the result you are excepting.

List<AggregateResult> result = [SELECT Name, count(Id) FROM Account GROUP BY Name Having count(Id)>1];