0

Very new to VF and controllers. Any help in the right direction is appreciated!

Business Use Case: Operations team reviews a form verifying Account information against information provided on a custom object, Partner App. The operations team must be able to edit fields on both objects and save these. No new records should be created. The custom object has a lookup to the Account and the relationship is one-to-one. Ideally, the operations team should access the Visualforce form from a Case related to the Account and it pops out as a separate window. However, I know that the code says that the page is referencing the custom object the user is on instead of the Case. To be clear, no updates will be made to the case, I would just like the button to get to this form to be on the case. The case is related to the custom object (1-to-1) and the Account.

Question/Problem: Do I use a standard controller with just an extension? Do I have to make a custom controller? How do I modify the controller I'm using to work? Most of the examples I'm finding online seem like they're inserting new records after saving. Both objects already exist and are related. I do not need to make any new records, just update the existing ones. There will only be one account and one custom object, so I do not need to get a list of any other objects.

Errors on the VFP: Unknown constructor 'PartnerAppExtensionController,PartnerAppExtensionController(ApexPages.StandardController controller)' Errors on the controller: Unexpected token 'update'

VFP:

<apex:page standardController="Partner_App__c" extensions="PartnerAppExtensionController" lightningStylesheets="true" showHeader="true">
    <apex:form>
    <apex:pageBlock title="Account Info">
        <apex:PageBlockSection columns="2">
                <apex:inputField label="Account Name" value="{!Partner_App__c.Account__r.Name}"/>
                <apex:inputField value="{!Account__.Marketing_Name__c}"/>
                <apex:outputField value="{!Partner_App__c.Account__r.Sales_Rep_Name_text__c}"/>
                <apex:outputField label="Manager Name" value="{!Partner_App__c.Account__r.Manager_Name__c}"/>
        </apex:PageBlockSection>
        </apex:pageBlock>
    <apex:pageBlock title="History">
        <apex:pageBlockSection columns="2">
            <apex:inputField label="Business Id" value="{!Partner_App__c.Business_Custom_Id__c}"/>
            <apex:inputField label="Date Formed" value="{!Partner_App__c.Date_of_Formation__c}"/>
            <apex:inputField label="Number of Employees" value="{!Partner_App__c.Number_of_Employees__c}"/>

        </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Custom Controller

public class PartnerAppExtensionController {

ApexPages.StandardController standardController; 
public Partner_App__c partnerAppObj {get;set;}
public Account accountObj {get;set;}

public PartnerAppExtensionController(ApexPages.StandardController standardContrtoller)
    {
        this.standardController = standardController;
        partnerAppObj = update partnerAppObj;
    }

 public void saveObjects(){
      update partnerAppObj;
      update accountObj;
 }

}

0

Not sure why you are updating in the constructor seems you just want to update the records because you are inputing and modifying data on the page. You could just go custom controller route but using a standard controller with an extension would work as well. Extensions in visualforce isnt like inheritence, they just construct your extensions with a standard controller reference. You have to get information from the standard controller to use it. For reference here is the documentation on standard controller type https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_pages_standardcontroller.htm


<apex:page standardController="Partner_App__c" extensions="PartnerAppExtensionController" lightningStylesheets="true" showHeader="true">
    <apex:form>
        <apex:pageBlock title="Account Info">
        <apex:PageBlockSection columns="2">
                <apex:inputField label="Account Name" value="{!Partner_App__c.Account__r.Name}"/>
                <apex:inputField value="{!Account__r.Marketing_Name__c}"/>
                <apex:outputField value="{!Partner_App__c.Account__r.Sales_Rep_Name_text__c}"/>
                <apex:outputField label="Manager Name" value="{!Partner_App__c.Account__r.Manager_Name__c}"/>
        </apex:PageBlockSection>
        </apex:pageBlock>
    <apex:pageBlock title="History">
        <apex:pageBlockSection columns="2">
            <apex:inputField label="Business Id" value="{!Partner_App__c.Business_Custom_Id__c}"/>
            <apex:inputField label="Date Formed" value="{!Partner_App__c.Date_of_Formation__c}"/>
            <apex:inputField label="Number of Employees" value="{!Partner_App__c.Number_of_Employees__c}"/>
        </apex:pageBlockSection>
        </apex:pageBlock>
        <apex:commandButton id="saveBtn" value="Save" action="{!saveObjects}" />  
    </apex:form>
</apex:page>

public class PartnerAppExtensionController {

    ApexPages.StandardController standardController; 
    public Partner_App__c partnerAppObj {get;set;}
    public Account accountObj {get;set;}

    public PartnerAppExtensionController(ApexPages.StandardController standardContrtoller)
    {
        this.standardController = standardController;
        this.partnerAppObj = (Partner_App__c)standardController.getRecord();
        this.accountObj = this.partnerAppObj.Account__c;
    }

    public void saveObjects(){
        update this.partnerAppObj;
        update this.accountObj;
    }
}
| improve this answer | |
  • thank you for the pointer. I didn't think I needed a custom controller, but was getting mixed up with the different examples I was trying to piece together. I appreciate the edits and will work from here! – Katboodle May 6 at 22:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.