Skip to main content

I have this code: that is generating a list of accounts for an "Account" Field  in a Visualforce Page. I would like it to generate a list of Accountst that have REE record type. Currently it shows Accounts of other record types than REE. Can I have some ideas of what I am doing wrong? 

//Method to get the Account List drop down

public List<SelectOption>getAccountOptions() {

ID rtAccount = Account.sObjectType.getDescribe().getRecordTypeInfosByName().get('REE').getRecordTypeId();

System.Debug('getAccountOptions Start');

//Execute query to get the respective roles

System.debug('<<<<<<< Get Account List Method Started >>>>>>>');

List<SelectOption> options = new List<SelectOption>();

for(Account acc: [SELECT ID, Name FROM Account WHERE RecordTypeId= rtAccount LIMIT 200])

{

options.add(new SelectOption(acc.Id,acc.Name));

}

System.debug('<<<<<<< Get Account List Method Completed >>>>>>>');

System.Debug('getAccountOptions End');

return options;

}

 
답변 2개
  1. 2020년 8월 11일 오후 9:22
    You may add a colon sign in the soql:

    for(Account acc: [SELECT ID, Name FROM Account WHERE RecordTypeId= :rtAccount LIMIT 200])
0/9000