+ Start a Discussion
RoyalRoyal 

how separate the id's based on recordsType ?

Hi All,

List<Account> ids=[select id from Account];
Set<ID> setids= Set<ID>();
Set<ID> SetAAA= Set<ID>();
Set<ID> SetBBB= Set<ID>();
for(Account acc: ids){
setids.add(acc.id);
I have all account id's in set object, so now i hvae to filter those id's based on recordtype.
like records type AAA then add to setAAA or Recordtype BBB then Add to SetBBB.

how to do code ?.

 
BALAJI CHBALAJI CH
Hi Royal,
Please find below code snippet using which you can separate the Record Ids based on record types.
 
Set<ID> setids= new Set<ID>();
Set<ID> SetAAA= new Set<ID>();
Set<ID> SetBBB= new Set<ID>();

for(Account ac: [select id, name, recordtype.Name from Account])
{
    if(ac.recordtype.Name == 'AAA')
    {
        SetAAA.add(ac.id);
    }
    
    if(ac.recordtype.Name == 'BBB')
    {
        SetBBB.add(ac.id);
    }
}
system.debug('SetAAA '+SetAAA);
system.debug('SetBBB '+SetBBB);
Here, lets suppose 'AAA' and 'BBB' are names of two record types in Account. When we excute this code, SetAAA contains all record Ids of record type 'AAA' and SetBBB contains all record Ids of record type 'BBB'.

Let us know if that helps you.


Best Regards,
BALAJI