You need to sign in to do that
Don't have an account?

Extending VF Opportunity Wizard
Good Morning All,
I am trying to create an Opportunity Wizard where a user clciks on a button from a specific account and is taken to a VF Page where they select a contact associated with the account from a drop down list and then enters the new opportunity info. They then click onNext which takes them to a new page and displays back the infor entered. I am able to dsiplay back the Account and contact info, but the opportunity info is getting lost.
Any suggestions?
VF Page 1 Code
<apex:page controller="newOpportunityController" tabStyle="Opportunity"> <apex:pageMessages id="msgs"/> <apex:sectionHeader title="New Customer Quick Quote" subtitle="Step 1 of 3"/> <apex:form > <apex:pageBlock title="Customer Information" mode="edit"> <apex:pageBlockButtons > <apex:commandButton action="{!step2}" value="Next"/> </apex:pageBlockButtons> <apex:pageBlockSection title="Account Information"> <!-- Within a pageBlockSection, inputFields always display with their corresponding output label. --> You are viewing the {!account.name} account. <p/> </apex:pageBlockSection> <apex:pageBlockSection title="Contacts"> <apex:selectList value="{!selectedContact}" multiselect="false"> <apex:selectOptions value="{!contactList}"/> </apex:selectList> </apex:pageBlockSection> <apex:pageBlockSection title="Opportunity Information"> <apex:inputField id="opportunityName" value="{!opportunity.name}"/> <apex:inputField id="opportunityAmount" value="{!opportunity.amount}"/> <apex:inputField id="opportunityCloseDate" value="{!opportunity.closeDate}"/> <apex:inputField id="opportunityStageName" value="{!opportunity.stageName}"/> <apex:inputField id="contactRole" value="{!role.role}"/> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
Controller Code
public class newOpportunityController { public PageReference step2() { PageReference pageRef = new PageReference('https://c.cs1.visual.force.com/apex/davidpage2?id=' + ApexPages.currentPage().getParameters().get('id')+ '&cid=' + selectedContact); pageRef.setRedirect(true); return pageRef; } Account account; Contact myContact; public List<Contact> contact{get;set;} public String selectedContact{get; set;} public List<SelectOption> contactList{get;set;} public Contact contacts{get; set;} Opportunity opportunity; OpportunityContactRole role; public newOpportunityController() { if (contactList == null) { List<Contact> contactee = [select id, name, contact.accountid from Contact where contact.accountid = :ApexPages.currentPage().getParameters().get('id')]; contactList = new List<SelectOption>(); for (Contact c : contactee) { contactList.add(new SelectOption( c.id, c.name )); } } } public Account getAccount() { return [select id, Name, Phone from Account where id = :ApexPages.currentPage().getParameters().get('id')]; } public Contact getMyContact() { return [select id, Name from Contact where id = :ApexPages.currentPage().getParameters().get('cid')]; } public Opportunity getOpportunity() { if(opportunity == null) opportunity = new Opportunity(); return opportunity; } public OpportunityContactRole getRole() { if(role == null) role = new OpportunityContactRole(); return role; } public PageReference test() { if (selectedContact!=null) { contacts=[select id, firstName,lastName,email from Contact where id = :selectedContact]; } return null; } }
VF Page 2
<apex:page controller="newOpportunityController" tabStyle="Opportunity"> <apex:sectionHeader title="New Customer Opportunity" subtitle="Step 2 of 3"/> <apex:form > <apex:pageBlock title="Confirmation"> <apex:pageBlockSection title="Account Information"> <apex:outputField value="{!account.name}"/> <apex:outputField value="{!account.site}"/> </apex:pageBlockSection> <apex:pageBlockSection title="Opportunity Information"> <apex:outputField value="{!opportunity.name}"/> <apex:outputField value="{!opportunity.amount}"/> <apex:outputField value="{!opportunity.closeDate}"/> </apex:pageBlockSection> <apex:pageBlockSection title="Contact Information"> <apex:outputField value="{!myContact.name}"/> <apex:outputField value="{!role.role}"/> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
Thanks for any help!
David
You should use page.davidpage2 to get a page reference instead of hardwiring the url for your server.
You shouldn't need to pass the id as a query parameter since it should be in the viewstate.
All Answers
Hi David,
There are two things because of which you cant show values:
1) The "opportunity" variable has no setter method to store the value once user enters them.
2) In the method "step2" when you move to next page you need to preserve the view state of the page at server-side. making the PageReference's variable "pageRef"' to setRedirect(true), the view state gets flushed and hence the user input data.
To tackle the problem you can follow following
1) declare "opportunity" variable as "public Opportunity opp {get; set;}" . This will automatically create getter and setter method. And for the getter code you have placed, you can do that in contructor.
2) please use pageRef.setRedirect(false); in step2 method
Hope this helps.
Obviously, I am not understanding what you are saying about the get and set. Can you show me in my code how this is done.
I apologize if I am being difficult.
David
Hi David,
Reposting your code with red sections bieng edited
I really don't understand why I still connot get this to work. I copied the new code into the controller and page 2 will still not display the opportunity information.
opportunity was fine the way it was... you don't need a setter since you never set opportunity; just fields within opoortunity.
But the setredirect comment above seems correct to me. If you redirect then you will load a new instance of the page and controller.
You should use page.davidpage2 to get a page reference instead of hardwiring the url for your server.
You shouldn't need to pass the id as a query parameter since it should be in the viewstate.
I hardwired the URL because I could not figure out how to get to the values in the Contact. Am I missing something obvious? I just don't understand why my values will not display.
Thanks,
David
I think I finally got it. I removed the hardwire of the URL and changed the following
public Contact getMyContact() {
return [select id, Name from Contact
where id = :selectedContact];
}
Now it appears to be working!
Thanks so much for everyones help!