• NavaForce
  • NEWBIE
  • 10 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
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:
  1. Created custom controller (see below)
  2. Created Visualforce page that references custom controller.
Errors:
  • 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"
Custom Controller
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!
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:
  1. Created custom controller (see below)
  2. Created Visualforce page that references custom controller.
Errors:
  • 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"
Custom Controller
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!