
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.poojaHello 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;
}
}
You will get to see :<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>
Note: Mark this as solution if that resolves your issue.