+ Start a Discussion
Debra Shoup 4Debra Shoup 4 

Visualforce page to create a custom object record from a related list

First, I’m not a developer and this is my first time attempting to create a Visualforce page and, I’m sure this is very basic to most on here, but I need some help. What I want to do: Override the “New” button on a custom child object to Contacts. The object is called Equipment Assignments and I want users to be able to request equipment from their Contact record in Salesforce. So I want to call the button “New Equipment Request.”  Basically, I want the user to create the record, the have it go through an approval process so the project manager can approve or disapprove the request.
I have created the VF page with the below code and when I preview it, everything looks right. I’ve created my custom button and placed it on the related list, shown in the image. However, when I click on the New Equipment Request button, I get the error “Id value 0033C000006pAjR is not valid for the Equipment_Assignments__c standard controller”. So, obviously I need to do more, but I don’t know what that is. I’ve read some posts about public class and wrapper class, but I’m not sure how to go about writing any of that or what exactly I would even need.

Also, I am using record types on the Equipment Assignments, so I need to incorporate that into the VF. I also want to pull in some custom information from the contact record, such as the Manager and Department. I’m not sure how to do that.
<apex:page standardController ="Equipment_Assignments__c">
<apex:form >
<apex:pageBlock title="Equipment Request">
  <apex:pageBlockSection title="Requestor Information">
    <apex:inputField value="{!Equipment_Assignments__c.name}"/>
    <apex:inputField value="{!Equipment_Assignments__c.Department__c}"/>
    <apex:inputField value="{!Equipment_Assignments__c.Assigned_To__c}"/>
    <apex:inputField value="{!Equipment_Assignments__c.Project__c}"/>
  <apex:pageBlockSection title="Request Information">
    <apex:inputField value="{!Equipment_Assignments__c.Start_Date__c}"/>
    <apex:inputField value="{!Equipment_Assignments__c.End_Date__c}"/> 
      <apex:commandButton value="Submit Request" action="{!save}"/>
User-added image
Alex SelwynAlex Selwyn
1) If you had overridden the 'New' button with the visualforce page for object 'New Equipment Request', clicking the 'New' button in the list view should take you to your visualforce page. Did you try that?

2) In your 'New Equipment Request' Did you use content source as 'URL' and provided the VF page url with /{!id} binding?
         a) This could be the reason for the error.
         b) If you need contact id from the calling page, you need to define a variable in your custom controller, say 'contactId' and pass the variable from the button,  something like this '/apex/newEquipmentPage?contactId={!id} --> the id will be dynamically binding from the calling contact page.