Skip to main content
pooja biswas a posé une question dans #Apex
Hi

My requirement is to bind recordtypes to an picklist and display in visual force page

I have the code show in this post.

public with sharing class recordtypepicklist

{

public list<SelectOption> getRecordTypes()

{

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

for(RecordType sRecordType:[select ID,Name from RecordType where SObjectType='Contact'])

{

options.add(new SelectOption(sRecordType.ID,sRecordType.Name));

}

return options;

}

}

I am getting an error as Error: Compile Error: Variable does not exist: ID at line 9 column 38

Its coming from the statement inside the for loop.

Pls let me know how to resolve this.

pooja

 
8 réponses
  1. 11 mai 2016, 05:09
    Hello Pooja,

    Try something like :

     

    public class MyController {

    list<SelectOption> options {get;set;}

    public String selectedCountry{get;set;}

    public String selectedRecordType{get;set;}

    public MyController(ApexPages.StandardController controller) { }

    public list<SelectOption> getRecordTypes()

    {

    options = new list<SelectOption>();

    for(RecordType rt: [SELECT Name FROM RecordType WHERE SobjectType = 'Account'])

    {

    if(rt != null)

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

    }

    System.debug('@@@ types List = '+options);

    return options;

    }

    }

    <apex:page controller="MyController">

    <apex:form >

    <apex:pageblock >

    <apex:outputLabel > Record Types : </apex:outputLabel>

    <apex:selectList size="1" value="{!selectedRecordType}">

    <apex:selectOptions value="{!RecordTypes }"/>

    </apex:selectList> <br/>

    </apex:pageblock>

    </apex:form>

    </apex:page>

    You will get to see :

    Hello Pooja,Try something like : public class MyController {list<SelectOption> options {get;set;}public String selectedCountry{get;set;}public String selectedRecordType{get;set;}public MyController(Ap

    Note:  Mark this as solution if that resolves your issue.
0/9000