You need to sign in to do that
Don't have an account?
Gary Stark 3
Visualforce page is not saving record into object after clicking save
Hi There,
I've created a visualforce page based on a custom object and an extension which enables this to be opened from the account screen.
Whenever I click "Save", I am redirected back to the account I invoked the visualforce page, however the record I created on the visualforce doesn't appear to be saving.
VF page:
<apex:page StandardController="Account" extensions="accountProp" sidebar="false">
<apex:sectionHeader title="Edit AccountProperty" />
<apex:form >
<apex:pageBlock title="Edit AccountProperty" id="thePageBlock" mode="edit">
<apex:pageMessages />
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}"/>
<apex:commandButton value="Cancel" action="{!cancel}"/>
</apex:pageBlockButtons>
<apex:actionRegion >
<apex:pageBlockSection title="Property Information" columns="1">
<apex:pageBlockSectionItem >
<apex:outputLabel value="Property_Name__c"/>
<apex:outputPanel >
<apex:inputField value="{!objB.Property_Name__c}">
<apex:actionSupport event="onchange" rerender="thePageBlock"
status="status"/>
</apex:inputField>
<apex:actionStatus startText="applying value..." id="status"/>
</apex:outputPanel>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:actionRegion>
<apex:pageBlockSection title="SVU Channel" columns="1"
rendered="{!objB.Property_Name__c == 'Sunrise ID'}">
<apex:inputField value="{!ObjB.Account__c}" required="true"/>
<apex:inputField value="{!objB.Sunrise_ID__c}" required="true"/>
<apex:inputField value="{!objB.Start_Date__c}" required="true"/>
<apex:inputField value="{!objB.Implementation_Date__c}" required="true"/>
</apex:pageBlockSection>
<apex:pageBlockSection title="SVU Channel" columns="1"
rendered="{!objB.Property_Name__c == 'SVU Site ID'}">
<apex:inputField value="{!objB.Account__c}" required="true"/>
<apex:inputField value="{!objB.SVU_SITE_ID__c}" required="true"/>
<apex:inputField value="{!objB.Start_Date__c}" required="true"/>
<apex:inputField value="{!objB.Implementation_Date__c}" required="true"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller:
public with sharing class accountProperty {
ApexPages.StandardController sc;
public Account_Property__c objB {get; set;}
public accountProperty(ApexPages.StandardController sc)
{
this.sc = sc;
objB = new Account_Property__c();
}
public ApexPages.PageReference SaveBoth()
{
insert objB;
return sc.Save();
}
}
I've created a visualforce page based on a custom object and an extension which enables this to be opened from the account screen.
Whenever I click "Save", I am redirected back to the account I invoked the visualforce page, however the record I created on the visualforce doesn't appear to be saving.
VF page:
<apex:page StandardController="Account" extensions="accountProp" sidebar="false">
<apex:sectionHeader title="Edit AccountProperty" />
<apex:form >
<apex:pageBlock title="Edit AccountProperty" id="thePageBlock" mode="edit">
<apex:pageMessages />
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}"/>
<apex:commandButton value="Cancel" action="{!cancel}"/>
</apex:pageBlockButtons>
<apex:actionRegion >
<apex:pageBlockSection title="Property Information" columns="1">
<apex:pageBlockSectionItem >
<apex:outputLabel value="Property_Name__c"/>
<apex:outputPanel >
<apex:inputField value="{!objB.Property_Name__c}">
<apex:actionSupport event="onchange" rerender="thePageBlock"
status="status"/>
</apex:inputField>
<apex:actionStatus startText="applying value..." id="status"/>
</apex:outputPanel>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:actionRegion>
<apex:pageBlockSection title="SVU Channel" columns="1"
rendered="{!objB.Property_Name__c == 'Sunrise ID'}">
<apex:inputField value="{!ObjB.Account__c}" required="true"/>
<apex:inputField value="{!objB.Sunrise_ID__c}" required="true"/>
<apex:inputField value="{!objB.Start_Date__c}" required="true"/>
<apex:inputField value="{!objB.Implementation_Date__c}" required="true"/>
</apex:pageBlockSection>
<apex:pageBlockSection title="SVU Channel" columns="1"
rendered="{!objB.Property_Name__c == 'SVU Site ID'}">
<apex:inputField value="{!objB.Account__c}" required="true"/>
<apex:inputField value="{!objB.SVU_SITE_ID__c}" required="true"/>
<apex:inputField value="{!objB.Start_Date__c}" required="true"/>
<apex:inputField value="{!objB.Implementation_Date__c}" required="true"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller:
public with sharing class accountProperty {
ApexPages.StandardController sc;
public Account_Property__c objB {get; set;}
public accountProperty(ApexPages.StandardController sc)
{
this.sc = sc;
objB = new Account_Property__c();
}
public ApexPages.PageReference SaveBoth()
{
insert objB;
return sc.Save();
}
}
Update your code like below
Let us know if this will help you
All Answers
<apex:page StandardController="Account" extensions="accountProp" sidebar="false">
<apex:sectionHeader title="Edit AccountProperty" />
<apex:form >
<apex:messages />
<apex:pageBlock title="Edit AccountProperty" id="thePageBlock" mode="edit">
<apex:pageMessages />
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}"/>
<apex:commandButton value="Cancel" action="{!cancel}"/>
</apex:pageBlockButtons>
<apex:actionRegion >
<apex:pageBlockSection title="Property Information" columns="1">
<apex:pageBlockSectionItem >
<apex:outputLabel value="Property_Name__c"/>
<apex:outputPanel >
<apex:inputField value="{!objB.Property_Name__c}">
<apex:actionSupport event="onchange" rerender="thePageBlock"
status="status"/>
</apex:inputField>
<apex:actionStatus startText="applying value..." id="status"/>
</apex:outputPanel>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:actionRegion>
<apex:pageBlockSection title="SVU Channel" columns="1"
rendered="{!objB.Property_Name__c == 'Sunrise ID'}">
<apex:inputField value="{!ObjB.Account__c}" required="true"/>
<apex:inputField value="{!objB.Sunrise_ID__c}" required="true"/>
<apex:inputField value="{!objB.Start_Date__c}" required="true"/>
<apex:inputField value="{!objB.Implementation_Date__c}" required="true"/>
</apex:pageBlockSection>
<apex:pageBlockSection title="SVU Channel" columns="1"
rendered="{!objB.Property_Name__c == 'SVU Site ID'}">
<apex:inputField value="{!objB.Account__c}" required="true"/>
<apex:inputField value="{!objB.SVU_SITE_ID__c}" required="true"/>
<apex:inputField value="{!objB.Start_Date__c}" required="true"/>
<apex:inputField value="{!objB.Implementation_Date__c}" required="true"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
I hope this will help you
You should replace action name in commandButton because in your ext controller
<apex:pageBlockButtons>
<apex:commandButton value="Save" action="{!SaveBoth}"/>
<apex:commandButton value="Cancel" action="{!cancel}"/>
</apex:pageBlockButtons>
if you found this answer helpful then please mark it as best answer so it can help others.
Thanks
Akshay
Look like you need to call SaveBoth function
<apex:page StandardController="Account" extensions="accountProp" sidebar="false">
<apex:sectionHeader title="Edit AccountProperty" />
<apex:form >
<apex:messages />
<apex:pageBlock title="Edit AccountProperty" id="thePageBlock" mode="edit">
<apex:pageMessages />
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}"/>
<apex:commandButton value="Cancel" action="{!cancel}"/>
</apex:pageBlockButtons>
<apex:actionRegion >
<apex:pageBlockSection title="Property Information" columns="1">
<apex:pageBlockSectionItem >
<apex:outputLabel value="Property_Name__c"/>
<apex:outputPanel >
<apex:inputField value="{!objB.Property_Name__c}">
<apex:actionSupport event="onchange" rerender="thePageBlock"
status="status"/>
</apex:inputField>
<apex:actionStatus startText="applying value..." id="status"/>
</apex:outputPanel>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:actionRegion>
<apex:pageBlockSection title="SVU Channel" columns="1"
rendered="{!objB.Property_Name__c == 'Sunrise ID'}">
<apex:inputField value="{!ObjB.Account__c}" required="true"/>
<apex:inputField value="{!objB.Sunrise_ID__c}" required="true"/>
<apex:inputField value="{!objB.Start_Date__c}" required="true"/>
<apex:inputField value="{!objB.Implementation_Date__c}" required="true"/>
<apex:inputField value="{!Account.Name}" />
</apex:pageBlockSection>
<apex:pageBlockSection title="SVU Channel" columns="1"
rendered="{!objB.Property_Name__c == 'SVU Site ID'}">
<apex:inputField value="{!objB.Account__c}" required="true"/>
<apex:inputField value="{!objB.SVU_SITE_ID__c}" required="true"/>
<apex:inputField value="{!objB.Start_Date__c}" required="true"/>
<apex:inputField value="{!objB.Implementation_Date__c}" required="true"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Update your code like below
Let us know if this will help you
Setting the same account on the account property was actually one of the requirements. It seems to work now. I changed the class as follows as sc.id was erroring and i wanted to return back to the account page after save. code below