I have overridden the new Opportunity page with a Visualforce page, which means there are 3 main routes for the Opportunity to be created:
- From an Account page
- From a Contact page
- From an Opportunity page
I have a dynamically generated picklist of Contacts, so the user can select a Contact at the point of Opportunity creation (creating the OpportunityContactRole). If the user selects route 2 I would like to set the value of this picklist to match the Contact record they clicked through from - the user should still be able to change if it desired.
The Contact Id is passed through so this is available for use. Page/Picklist snippet:
<apex:selectList value="{!SelectedCon}" size="1" label="Select Contact">
<apex:selectOptions value="{!con}"/>
<apex:actionSupport event="onchange" reRender="test"/>
</apex:selectList>
Controller snippet:
Public List<SelectOption> getCon(){
List<SelectOption> conOptions = new List<SelectOption>();
conOptions.add(new SelectOption('','Please select a Contact'));
List<Contact> conList = new List<Contact>([SELECT Id, Name FROM Contact Where AccountId = :AccId]);
For (Contact cn : conList){
conOptions.add(new SelectOption(cn.Id,cn.Name));
}
conOptions.add(new SelectOption('New Contact','New Contact')); //Option to create a new Contact
return conOptions;
}
How can I set the picklist to match the passed conid upon pageload? Happy to look at javascript but I have very little experience of it.