0

enter image description hereI am trying to create a method do pull all accounts that have a record type of REE. I have the following lines and it does not work, because all accounts come up. This is for a Visualforce Page where a field is an "Account" field with pick list values of Accounts.

//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;
       
    }
3
  • 2
    easier would be [SELECT .... FROM Account WHERE RecordType.DeveloperName = 'REE']
    – cropredy
    Aug 11, 2020 at 23:53
  • Is it possible to create a method with If Then statement. The Account list that is displayed in the Pick list to show accouns based on the Record type selected in the other pic list. I will attach a screen shot of it. Aug 12, 2020 at 13:50
  • i don't see where the Account Record Type is shown on the form - only a Contact Record Type
    – cropredy
    Aug 13, 2020 at 19:13

1 Answer 1

0

Try to get recordtype by this code Id rtAccount = Schema.sObjectType.Account.getRecordTypeInfosbyName().get('REE').getRecordTypeId(); OR Id rtAccount = [select Id from RecordType where Name = 'REE' and sobjecttype = 'Account'].Id;

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .