function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
CapCbRMCapCbRM 

standardController question, Save button function

Hi,

 

I currently have a VF page that pulls from a custom object called Milestone__c, I would like to use this page on my Opportunity layout.

 

I currently have the standardController set to Opportunity so it can be displayed on the Opp layout.

 

The object heirarchy is as follows:

 

Opportunity

Schedule

Milestones

 

The current VFpage is as follows:

 

<apex:page standardController="Opportunity" extensions="PullMilestones" showHeader="false" >
<apex:form >

<apex:pageBlock title="Milestones" mode="edit">
<apex:pageMessages />

<apex:pageblockButtons location="top">
<apex:commandButton value="Save" action="{!save}" />
<apex:commandButton value="Cancel" action="{!cancel}"/>
</apex:pageBlockButtons>

<apex:pageBlockTable value="{!milestones}" var="m">

<apex:column headerValue="Name">
<apex:inputField value="{!m.Name}"/>
</apex:column>

<apex:column headerValue="Duration">
<apex:inputField value="{!m.Duration__c}"/>
</apex:column>

<apex:column headerValue="Status">
<apex:inputField value="{!m.Status__c}"/>
</apex:column>

</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>

</apex:page>

 

The extension controller is:

 

public Class PullMilestones{

public PullMilestones(ApexPages.StandardController controller) {
}

public Milestone__c[] getMilestones() {
Milestone__c[] milestones;

milestones = [SELECT ID, Name, Duration__c, Status__c FROM Milestone__c WHERE Opportunity__c = :ApexPages.currentPage().getParameters().get('id')
ORDER BY CreatedDate];

return milestones;
}

}

 I would like to use the Save button, being that page loads in edit mode. With the standardController set to Opportunity I get this: You cannot call save() on a null object

 

If I set the standardController to Milestone__c I get an error saying "Content cannot be displayed: Id value 006Q0000003hx4D is not valid for the Milestone__c standard controller" (the ID being the test Opp ID I am testing on)

 

Anyone have any input? I've been flipping through the book trying to figure out the best way to handle this.

 

Still learning, anything will help. Thanks in advance.

 

Best Answer chosen by Admin (Salesforce Developers) 
CapCbRMCapCbRM

Bob,

 

Thanks for your input. That is exactly what it was, the ID was just giving an error because it didn't exist.

 

I solved the issue here:

 

Custom Controller, Save Function

 

it required creating a save method within an extension and updating the queried array.

All Answers

bob_buzzardbob_buzzard

That's a little strange, I would expect the Opportunity associated with the id you pass to the page to be loaded.

 

That said, you aren't actually doing anything with the Opportunity on the page, so it may be that the record isn't pulled from the database under those circumstances. 

 

Can I ask what you are hoping to achieve with the save?  If you are intending to save the updated milestones, then the standard controller save won't give you that, as it would only save the Opportunity. 

CapCbRMCapCbRM

Bob,

 

Thanks for your input. That is exactly what it was, the ID was just giving an error because it didn't exist.

 

I solved the issue here:

 

Custom Controller, Save Function

 

it required creating a save method within an extension and updating the queried array.

This was selected as the best answer