I have created a custom lookup field on the Order object to the Opportunity because we want to create Orders from Opps and not Accounts.
I have also created a Visualforce page for Orders and am attempting to get both the Opportunity Name and the Account name to populate when creating a new record.
I have tried everything that I can find but cannot figure this out and I know it is something simple that I am missing.
Here is some of the VF page:
<apex:page showHeader="true" Standardcontroller="Order" extensions="SaveAndAddProductControllerExtension">
<apex:sectionHeader title="New Order" subtitle=""/>
<apex:form >
<apex:pageBlock title="New Order" mode="edit">
<apex:pageBlockButtons location="top">
<apex:commandButton value="Save & Add Product" action="{!save}"/><apex:commandButton value="Cancel" action="{!cancel}"/>
</apex:pageBlockButtons>
<apex:pageBlockButtons location="bottom">
<apex:commandButton value="Save & Add Product" action="{!save}"/><apex:commandButton value="Cancel" action="{!cancel}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Order Information" columns="2">
<apex:inputField value="{!order.Opportunity_Name__r.Name}"/>
<apex:inputField value="{!order.AccountId}"/>
<apex:inputField value="{!order.EffectiveDate}" required="true"/>
<apex:inputField value="{!order.Database__c}" required="false"/>
<apex:inputfield value="{!order.EndDate}" required="true"/>
<apex:inputField value="{!order.Status}" required="true"/>
<apex:pageBlockSectionItem ></apex:pageBlockSectionItem>
<apex:inputField value="{!order.Price_List__c}" required="false"/>
</apex:pageBlockSection>
And my class:
public class SaveAndAddProductControllerExtension {
public Order order;
public String oppName;
public SaveAndAddProductControllerExtension(ApexPages.StandardController controller) {
this.order = (Order)controller.getRecord();
this.oppName = order.Opportunity_Name__r.Name;
}
public String getoppName() {
{
oppName = [SELECT Name FROM Opportunity WHERE Id = :order.Opportunity_Name__c].Name;
}
return oppName;
}
Order ord;
public Order getOrder() {
if(ord == null) ord = new Order();
ord.Opportunity_Name__c = ord.Opportunity_Name__r.Id;
ord.Account = ord.Opportunity_Name__r.Account;
ord.EffectiveDate = System.Today();
ord.EndDate = System.Today() + 1095;
ord.Status = 'Open';
return ord;
}
public PageReference save() {
try {
system.debug('*************' +Ord);
insert Ord;
PageReference neword = new PageReference('/apex/orderProductEntry?Id='+Ord.Id);
system.debug('test::::::::::::' + neword);
neword.setRedirect(true);
return neword;
}
catch (DMLException e) {
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, 'Error creating new order.'));
return null;
}
return null;
}
}
I really wanted to figure this out on my own, but I am at my breaking point. Any help would be immensely appreciated.