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
MeerMeer 

Edit page overidden

Hi,

 

I have made a VFPage and is overriden to the edit button. I am not able to update the record, as my task is to update the record and to redirect the page to the home.

 

*********CONTROLLER*********

public class Line_Manager
{
public Fin_Journal__c journal {get;set;}

//Constructors
public Line_Manager ()
{
journal = new Fin_Journal__c();
}

 

public Line_Manager (ApexPages.StandardController controller)
{
journal = new Fin_Journal__c();
}

 

//Updating Journal [View Journal]

public PageReference UpdateJournal()
{
journal = [SELECT Name FROM Fin_Journal__c WHERE id =: ApexPages.currentPage().getParameters().get('id')];
update journal;

PageReference page = new PageReference ('https://ap1.salesforce.com/a0I/o');
return page;
}

//Cancel Function
public PageReference Cancel()
{
PageReference page = new PageReference ('https://ap1.salesforce.com/a0I/o');
return page;
}

 

}

 

 

 

*********VFPage*********

 

<apex:page standardController="Fin_Journal__c" extensions="Line_Manager">
<apex:form >

<table border="0" cellspacing = "0" cellpadding= "2">
<tr><td></td></tr><tr><td></td></tr><tr>
<td><apex:image url="https://c.ap1.content.force.com/servlet/servlet.FileDownload?file=01590000000O4Wx" width="35" height="40"/></td>
<td>
<apex:outputText ><font size="1" color="#606060" face="Arial"><b>Journal</b></font></apex:outputText><br/>
<apex:outputText ><font size="5" color="Black" face="Arial"><apex:outputField value="{!Fin_Journal__c.Name}"/> </font></apex:outputText>
</td>
</tr><tr><td></td></tr><tr><td></td></tr>
</table>

<center>
<apex:commandButton value="Save" action="{!UpdateJournal}" />&nbsp;&nbsp;
<apex:commandButton value="Delete"/>&nbsp;&nbsp;
<apex:commandButton value="Cancel" action="{!Cancel}"/>
</center>

<br/>

<apex:pageBlock mode="inlineEdit" title="Journal Detail">
<apex:pageBlockSection columns="2">
<apex:outputField value="{!Fin_Journal__c.Period__c}"/>
<apex:outputLabel ></apex:outputLabel>
<apex:outputField value="{!Fin_Journal__c.Journal_Date__c}"/>
<apex:outputLabel ></apex:outputLabel>
<apex:outputField value="{!Fin_Journal__c.Card__c}"/>
<apex:outputLabel ></apex:outputLabel>
<apex:outputField value="{!Fin_Journal__c.Description__c}"/>
</apex:pageBlockSection>
</apex:pageBlock>

<apex:pageBlock mode="inlineEdit" title="Journal Settings">
<apex:pageBlockSection columns="2">
<apex:outputField value="{!Fin_Journal__c.Journal_Name__c}"/>
<apex:outputLabel ></apex:outputLabel>
<apex:outputField value="{!Fin_Journal__c.Batch__c}"/>
<apex:outputField value="{!Fin_Journal__c.Source__c}"/>
<apex:outputField value="{!Fin_Journal__c.Currency__c}"/>
<apex:outputField value="{!Fin_Journal__c.Status__c}"/>
<apex:outputField value="{!Fin_Journal__c.Category__c}"/>
<apex:outputField value="{!Fin_Journal__c.Include_Tax__c}"/>
</apex:pageBlockSection>
</apex:pageBlock>

</apex:form>

</apex:page>

 

 

Thanks

 

Regards,

Meer


Navatar_DbSupNavatar_DbSup

Hi,

 

Place your query in class constructor instead of UpdateJournal method.

Try the below modified code snippet as reference:

 

*********CONTROLLER*********

 

public class Line_Manager

{

public Fin_Journal__c journal {get;set;}

 

//Constructors

public Line_Manager ()

{

journal = new Fin_Journal__c();

journal = [SELECT Name FROM Fin_Journal__c WHERE id =: ApexPages.currentPage().getParameters().get('id')];

}

 

 

 

public Line_Manager (ApexPages.StandardController controller)

{

journal = new Fin_Journal__c();

}

 

 

 

//Updating Journal [View Journal]

 

public PageReference UpdateJournal()

{

update journal;

 

PageReference page = new PageReference ('https://ap1.salesforce.com/a0I/o');

return page;

}

 

//Cancel Function

public PageReference Cancel()

{

PageReference page = new PageReference ('https://ap1.salesforce.com/a0I/o');

return page;

}

 

 

 

}

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

 

MeerMeer

I tried it  before and now even but it's not working..

 

Regards,

Meer

Navatar_DbSupNavatar_DbSup

Hi,

 

First of all query all fields which you want to display and update from the vf page.

 

Change the constructor

 

//Constructors

public Line_Manager ()

{

journal = new Fin_Journal__c();

journal = [SELECT   idname period__c,Journal_Date__c,Card__c,Journal_Name__c,Batch__c,Source__c,Status__c,Category__c,Include_Tax__c FROM Fin_Journal__c WHERE id =: ApexPages.currentPage().getParameters().get('id')];

}

 

In Vf page use the journal instead of Fin_Journal__c


For example

<apex:outputField value="{! journal.Period__c}"/>

 

 

 

MeerMeer

Hi,

 

Actually I have use the same for Detai view as well so from Recent Journal screen when I click the hyperlink it opens the detial view of that record and that page is over ridden thus, the way you are telling me won't work here.

 

Regards,

Meer