I overrode the new button with a custom VisualForce page but the problem is when I click the new button on the related list (Cases) it use to pre-populate the contact and account names. Now that I have a custom page it does not. I tried URL hacking and I can't get it to pre-populate. Even if I did successfully get the URL hack to populate the field I don't think I would be able to tell the new button on the related to pass the parameters needed. The id is j_id0:j_id29:j_id30:referralBasics:accountId and whenever I add the query string to the url and put a value there it shows up blank.
So I then tried to just query everything I need and then populate the fields via my controller but now when they press save it doesn't save the fields that were prepopulated (because they are stored in controller variable instead on the Case Page variable). Here's what I have for the second option. It populates the fields but when saving it doesn't save correctly and I tried overriding the save but that isn't working correctly:
public class RHX_Custom_Master_New_Controller {
private ApexPages.StandardController sc;
public Account company {get; set;}
public Contact employee {get; set;}
public boolean hasEmployee{get;set;}
public boolean hasCompany{get;set;}
public RHX_Custom_Master_New_Controller.RHX_Custom_Master_New_Controller(ApexPages.StandardController controller) {
sc = controller;
List<Contact> cons = [select Name from Contact WHERE Id = :ApexPages.currentPage().getParameters().get('cas3_lkid') limit 1];
if(cons.size() > 0) {
employee = cons[0];
hasEmployee = true;
} else
hasEmployee = false;
List<Account> accts = [select Name from Account WHERE Id = :ApexPages.currentPage().getParameters().get('cas4_lkid') limit 1];
if(accts.size() > 0) {
company = accts[0];
hasCompany = true;
} else
hasCompany = false;
// ApexPages.currentPage().getParameters().get('cas14')
}
public PageReference save() {
PageReference detailPage = sc.save();
// this is a syntax error but I need to change this case or get reference to the case being saved in the vf page and change the value here
//Case.Contact.Name = employee.Name;
if (detailPage != null) {
// Construct URL of edit page or whatever other page you want
PageReference editPage = new PageReference(detailPage.getUrl());
return editPage;
} else {
return detailPage;
}
}
}
Here's the VF page section that is needed:
<apex:form >
<apex:pageBlock mode="edit" title="Master Referral Record Edit">
<apex:pageBlockButtons location="both">
<apex:commandButton value="Save" action="{!Save}" />
<apex:commandButton value="Cancel" action="{!Cancel}" />
</apex:pageBlockButtons>
<apex:pageBlockSection id="referralBasics" title="Referral Basics" columns="2" collapsible="true">
<apex:inputField id="preferredFirstName" value="{!Case.Preferred_First_Name__c}"/>
<apex:inputField id="owner" value="{!Case.Owner.Name}"/>
<apex:inputField id="contactId" value="{!employee.Name}"/>
<apex:outputText ></apex:outputText>
<apex:inputField id="accountId" value="{!company.Name}"/>
<apex:outputText ></apex:outputText>
<apex:inputField id="parentId" value="{!Case.ParentId}"/>
</apex:pageBlockSection>
Any ideas?