I'm trying to create a visualforce page which clones the record type selection page when creating new Opportunities. I'd like the page to display opp record types based on the related account record type. Below is the code but I'm getting error this error:
Variable does not exist:currentAccount.RecordType.DeveloperName
public class myController {
public List<SelectOption> opts {get;set;}
private String oType {get;set;}
public Id recTypeId {get;set;}
myController(){
oType = 'Opportunity';
}
public List<SelectOption> myOptions() {
opts = new List<SelectOption>();
opts.add(new SelectOption('','--Please Select Record Type --'));
for(RecordType rts : [Select Id, DeveloperName, Name From RecordType Where SObjectType = 'Opportunity']) {
opts.add(new SelectOption(rts.id,rts.name));
}
Map<String,List<String>> mapping = new Map<String,List<String>>();
mapping.put('Small_Medium_Sized_Business', new List<String>{'Defined_Benefit_Retirement','Defined_Contribution_Retirement'});
return opts;
}
}
Edit to add Visual Force Page Code:
<apex:page standardController="Account">
<apex:form >
<apex:selectList value="{!recTypeID}" size="1">
<apex:selectOptions value="{!myOptions}">
</apex:selectOptions>
</apex:selectList>
<apex:commandButton value="Next" Action="{!continue}"/>
</apex:form>
</apex:page>
Can someone help me with this? Thanks!
Best Answer
Where are your getters and setters in the controller? I see no references to
currentAccount.RecordType.DeveloperName
except in your 2nd query. Your controller hasn't built this map and it's not done aget
of the Account ID's orOpportunity.Account
needed to build it.You have a
return options
statement, but what are you returning those options to? How are you planning to get them back to your VF page?Once you do that, I'm assuming you'll need to get your selection(s) back to your controller for cloning which you'll need to add another method for.
I highly recommend you take a look at the VisualForce Workbook, the VisualForce Developer's Guide and the Force.com Apex Code Developer's Guide for more on VisualForce pages and custom controllers.
Edit in response to comments...
In your VisualForce page,
The above should refer to your custom controller and look something more like this:
Error: Unknown property
AccountStandardController.recTypeID
is in part because you're specifying the wrong controller. Once you do have the correct controller, I suspect you'll still see errors because what you're returning and "setting" is not the recordtype.ID. Your controller as written above, appears to "return" or set "opts" which you have listed in your page as!myOptions
which doesn't appear to me to be what you're setting.Again, I highly recommend you take a look at the VF Workbook and other references I pointed you to which might help get you quickly sorted if you'll only spend a few minutes with them.