You need to sign in to do that
Don't have an account?
Denise Crosby
add "+ New Contact" to SelectOption list
Hello. I have an Apex class and Visual Force page to create an event, where the user first selects the Account and then the page will display only the Contacts associated with that Account. I need my List<SelectionOption> to show the "+ New Contact" option that appears when you create a regular event in Salesforce. Is there a way to do this?
public List<SelectOption> contactOptions { get { if ( contactOptions == null && dummyContact.AccountId != null ) { contactOptions = new List<SelectOption>(); contactOptions.add( new SelectOption( 'null', '--None--' ) ); for ( Contact contact : [ SELECT Id, Name FROM Contact WHERE AccountId = :dummyContact.AccountId ] ) { contactOptions.add( new SelectOption( contact.Id, contact.Name ) ); } } return contactOptions; } private set; }
<apex:actionSupport event="onChange" action="{!createNewContact}" reRender="tableShow"/>
<apex:selectList value="{!SelectedContact}" size="1">
<apex:actionSupport event="onChange" action="{!createNewContact}" reRender="tableShow"/>
<apex:selectOptions value="{!contactOptions}"/>
</apex:selectList>
Method should be like below
public pageReference createNewContact()
{
if(SelectedContact=='New Contact')
{
return new pageReference('/003/e');
}
return null
}
Let us know if this will help you
All Answers
Thanks for your reply. Yes, that works to add "+ New Contact" to the drop down but I need to figure out how to navigate to the New Contact page and navigate back after the new contact is added. I am new to coding Apex, so please let me know if you have any advice on this. Thank you.
<apex:actionSupport event="onChange" action="{!createNewContact}" reRender="tableShow"/>
<apex:selectList value="{!SelectedContact}" size="1">
<apex:actionSupport event="onChange" action="{!createNewContact}" reRender="tableShow"/>
<apex:selectOptions value="{!contactOptions}"/>
</apex:selectList>
Method should be like below
public pageReference createNewContact()
{
if(SelectedContact=='New Contact')
{
return new pageReference('/003/e');
}
return null
}
Let us know if this will help you
<apex:commandButton value="New Contact" action="{!URLFOR($Action.Contact.NewContact)}"/>