+ Start a Discussion
sagar077sagar077 

Hello, Please me on this requirement. Create a set to find a unique industry(field on account) from the account. 

Hello, Please me on this requirement. Create a set to find a unique industry(field on account) from the account. 
Check this code and tell me where I am wrong.

Set <Account> indust = new Set <Account> ();
Account [] newindus = [SELECT Id,Name FROM Account WHERE Industry = 'Agriculture'];                  
set<Account> aa = new set<Account>();
for (Account aa : indust)
{
indust.add(aa.Industry);
}
System.debug('Name The Unique Industry ' + aa );

I am not getting the error please help me ..thanks
AnudeepAnudeep (Salesforce Developers) 
With the following code you will have a set of unique industries
 
List<Account> lstAccount = new List<Account>();

Set<String> Industry= new Set<String>();

lstAccount = [SELECT Id, Industry, Name FROM Account] ;

for (Integer i = 0; i< lstAccounts.size(); i++)

{

    setAccountName.add(lstAccount[i].Industry); 

}

If you find this information helpful. please mark this answer as Best. It may help others in the community. Thank You!

Anudeep
 
sagar077sagar077
Hello Anudeep,
its not working