You need to sign in to do that
Don't have an account?
NavaForce
Unknown Property Error Using Custom Controller in Visualforce Page
I am a brand new developer starting from scratch. I've been working on the following issue for over a month and would greatly appreciate some help.
Data Model: I have a parent object called Financial_Month__c with chid records of Workout__c. This is a master-detail relationship on the Workout__c object.
Desired Endstate: Override New standard button on Workout__c object tab with a custom Visualforce page. On that page, prepopulate the parent (Financial_Month__c) lookup value.
Process:
Visualforce Page
I'm getting ready to quit on this project but wanted to see if someone could help me first.
Any thoughts you have would be greatly appreciated. Thank you in advance!
Data Model: I have a parent object called Financial_Month__c with chid records of Workout__c. This is a master-detail relationship on the Workout__c object.
Desired Endstate: Override New standard button on Workout__c object tab with a custom Visualforce page. On that page, prepopulate the parent (Financial_Month__c) lookup value.
Process:
- Created custom controller (see below)
- Created Visualforce page that references custom controller.
- Before I enter the workoutMonth variable in the Visualforce page, I receive the following error: "Unknown property 'custom_Controller_New_Workout_VF_Page.Workout__c"
- After I enter the workoutMonth variable in the pageBlockSection, I receive the following error: "Invalid field Workout__c for SObject Financial_Month__c"
public class custom_Controller_New_Workout_VF_Page { //Create a list to store Workout Month records. public Financial_Month__c workoutMonth {get; set;} public custom_Controller_New_Workout_VF_Page() { //Get current Financial Month record. workoutMonth = [SELECT Id, Name, CreatedDate, Current_Month__c, RecordType.DeveloperName FROM Financial_Month__c WHERE RecordType.DeveloperName = 'Workout_Month' AND Current_Month__c = True ORDER By CreatedDate DESC LIMIT 1]; } public Financial_Month__c getworkoutMonth() { return workoutMonth; } public PageReference save() { update workoutMonth; return null; } }
Visualforce Page
<apex:page controller="custom_Controller_New_Workout_VF_Page" lightningStylesheets="true"> <apex:form> <apex:pageBlock mode="edit"> <apex:pageMessages /> <apex:pageBlockSection columns="1" title="🏋️♂️ New Workout" collapsible="false" showHeader="true"> <apex:outputField value="{!workoutMonth.Workout__c.Workout_Month__c}"/> <apex:inputField value="{!Workout__c.Date__c}" required="true"/> <apex:inputField value="{!Workout__c.Workout__c}" required="true"/> <apex:inputField value="{!Workout__c.Rest_Reason__c}"/> </apex:pageBlockSection> <apex:pageBlockButtons location="bottom"> <apex:commandButton action="{!save}" value="Save"/> </apex:pageBlockButtons> </apex:pageBlock> </apex:form> </apex:page>
I'm getting ready to quit on this project but wanted to see if someone could help me first.
Any thoughts you have would be greatly appreciated. Thank you in advance!
Also I suggest you to try Trailhead first.
All Answers
You need to use StandardController and extension to replace New button, while you are using controller so it won't work.
I suggest you to check below trailhead links:
https://trailhead.salesforce.com/content/learn/modules/visualforce_fundamentals
https://trailhead.salesforce.com/en/content/learn/projects/workshop-override-standard-action/override_4
If this answer helps you, please mark it as accepted.
Regards,
Tushar Sharma
https://newstechnologystuff.com/
Revised Visualforce Page Controller Extension Class Can you please tell me what I am still doing wrong? Thank you!
Also I suggest you to try Trailhead first.
I am setting this as best answer.