1

I am trying to create a simple VF page that creates a Physician's Note on save.

I am having trouble exposing this VF page on the account object since the standard controller is set to Physicians_note__c

Physicians Note is a child to the Account.

Below is my code:

<apex:page StandardController="Physicians_Note__c">
<apex:form >
    <apex:pageBlock title="Physician's Note" mode="edit">
        <apex:pageBlockButtons >
            <apex:commandButton action="{!save}" value="Save"/>
        </apex:pageBlockButtons>
        <apex:pageBlockSection title="My Content Section" columns="2">
            <apex:inputField Label="Subjective" value="{!Physicians_Note__c.Subjective__c}" style="width:500px"/>
            <br></br>
            <apex:inputField Label="Objective" value="{!Physicians_Note__c.Objective__c}" style="width:500px"/>
            <br></br>
            <apex:inputField Label="Assessment" value="{!Physicians_Note__c.Assessment__c}" style="width:500px"/>
            <br></br>
            <apex:inputField Label="Plan" value="{!Physicians_Note__c.Plan__c}" style="width:500px"/>
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:form>     

enter image description here

I am trying to put the VF page on the account page using the Edit page option:

enter image description here

Can anyone help me expose this VF page on the account page while still creating the Physician's Note when pressing save?

Thank you

2

Any page that you want to include in the Account layout must use that standard controller:

<apex:page standardController="Account">

If you want to add a child object, you may need to add an extension. The code would look like:

public with sharing class AddPhysicianNoteExtension
{
    public Physician_Note__c note { get; private set; }
    public AddPhysicianNoteExtension(ApexPages.StandardController controller)
    {
        // this constructor must be defined to add the extension to the page
        Id accountId = controller.getId();
        note = new Physician_Note__c(Account__c=accountId);
    }
    public void save()
    {
        // you will have to define this logic
    }
}

Then you would add the extension to the page:

<apex:page standardController="Account" extensions="AddPhysicianNoteExtension">

As far as that save method is concerned, the most basic implementation would just be:

insert note;

But it is highly advisable to add some error handling. The simplest approach there would just be:

try
{
    insert note;
    ApexPages.addMessage(new ApexPages.Message(
        ApexPages.Severity.Confirm, 'Record saved!'
    ));
}
catch (DmlException dmx)
{
    ApexPages.addMessages(dmx);
}

To surface these messages, you will have to add an <apex:pageMessages> tag and make sure to rerender it on save.

<apex:pageMessages id="msgs" />
...
<apex:commandButton action="{!save}" value="Save" rerender="msgs" />
  • Thank you so much Adrian, i got the Vf page successfully on the account object. my last question would be, when i press the save button nothing happens. But when i refresh the page the new record shows in the associated related list (Found underneath the vf component). Can i set it to refresh the page on save so i can show that the record has been created without having to manually refresh? – Alex Waddell Mar 15 '17 at 17:40
  • You need to have your save button rerender an <apex:pageMessages> tag. – Adrian Larson Mar 15 '17 at 17:42
  • @Alex If this answer addressed your problem, please consider accepting it by clicking on the check mark/tick to the left of the answer, turning it green. This marks the question as resolved to your satisfaction, and awards reputation both to you and the person who answered. If you have >= 15 reputation points, you may also upvote the answer if you wish. There is no obligation to do either. – Adrian Larson Mar 15 '17 at 17:50
0

you need to add Account as standard Controller and your custom controller as an extension. This will then enable you add this page on account object layout.

<apex:page standardController="Account" extensions="Physicians_Note__c">

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.