You need to sign in to do that
Don't have an account?
How to insert record with VF Page
Hi, I have the following class and page, I have added the Page in the detail pagelayout of custom object 'Journal'. Now can anybody tell me how can I auto fill the Journal__c field in the VfPage with the current Journal detail page. Plus I want to save this New Line for thr current Journal. Please help me
********** Class **********
public class Fin_LineManager
{
public Line__c newLine{get; set;}
public Fin_LineManager(ApexPages.standardController stdn)
{
newLine = new Line__c();
}
public PageReference save()
{
insert newLine;
return null;
}
}
********** Page **********
<apex:page standardController="Fin_Journal__c" extensions="Fin_LineManager">
<apex:form >
<apex:pageBlock >
<apex:panelGrid columns="4" cellspacing="2" cellpadding="1">
<apex:outputLabel >Journal ID: </apex:outputLabel>
<apex:outputLabel value="{!newline.Journal__c}"/>
<apex:outputLabel >Credit: </apex:outputLabel>
<apex:inputField value="{!newline.Credit__c}"/>
<apex:outputLabel >Debit: </apex:outputLabel>
<apex:inputField value="{!newline.Debit__c}"/>
<apex:outputLabel >Description: </apex:outputLabel>
<apex:inputField value="{!newline.Description__c}"/>
<apex:commandButton action="Fin_LineManager.save()" value="Save"/>
</apex:panelGrid>
</apex:pageBlock>
</apex:form>
</apex:page>
NOTE: I have a related list of 'Line' in the Journal Page, I want to Update and refresh that realted list as well so the user can see that New Line has been added successfully.
Thanks
Meer
Sorry there was a mistake in calling save function it should be action="{!save}" and the constructor can go like this:
public Fin_LineManager(ApexPages.standardController stdn)
{
newLine = new Line__c(Journal__c = ApexPages.currentPage().getParameters().get('id'));
}
All Answers
Hi,
Try the following code ----
********** Class **********
public class Fin_LineManager
{
public Line__c newLine{get; set;}
public string id{get;set;}
public Fin_LineManager(ApexPages.standardController stdn)
{
newLine = new Line__c();
id=ApexPages.CurrentPage.getParameters().get('id);
newLine.Journal__c=id;
}
public PageReference save()
{
insert newLine;
return null;
}
}
********** Page **********
<apex:page standardController="Fin_Journal__c" extensions="Fin_LineManager">
<script>
function goto()
{
parent.location.href='/{!id}';
}
</script>
<apex:form >
<apex:pageBlock >
<apex:panelGrid columns="4" cellspacing="2" cellpadding="1">
<apex:outputLabel >Journal ID: </apex:outputLabel>
<apex:outputLabel value="{!newline.Journal__c}"/>
<apex:outputLabel >Credit: </apex:outputLabel>
<apex:inputField value="{!newline.Credit__c}"/>
<apex:outputLabel >Debit: </apex:outputLabel>
<apex:inputField value="{!newline.Debit__c}"/>
<apex:outputLabel >Description: </apex:outputLabel>
<apex:inputField value="{!newline.Description__c}"/>
<apex:commandButton action="{!save}" value="Save" onComplete="goto();"/>
</apex:panelGrid>
</apex:pageBlock>
</apex:form>
</apex:page>
Sorry there was a mistake in calling save function it should be action="{!save}" and the constructor can go like this:
public Fin_LineManager(ApexPages.standardController stdn)
{
newLine = new Line__c(Journal__c = ApexPages.currentPage().getParameters().get('id'));
}