You need to sign in to do that
Don't have an account?
VF page for a NEW record on a custom object
I am new to writing VF pages. I have a VF page and Apex Class that I have written to override the NEW button for my custom object. However, all that displays are the buttons at the top and bottom of the page, no fields. Can anyone take a look and point me in the right direction to correct my issue?
Thank you
VF Page -
<apex:page standardController="STG_Payment_Requests__c" extensions="ContentNewSTGPR">
<apex:sectionHeader title="STG Payment Request" subtitle="{!STG_Payment_Requests__c.name}"/>
<apex:form >
<apex:pageBlock title="New STG Payment Request">
<apex:pageBlockButtons location="top">
<apex:commandButton value="Save" action="{!save}"/>
<apex:commandButton value="Update" action="{!quicksave}"/>
<apex:commandButton value="Cancel" action="{!cancel}"/>
</apex:pageBlockButtons>
<apex:pageBlockButtons location="bottom">
<apex:commandButton value="Save" action="{!save}"/>
<apex:commandButton value="Update" action="{!quicksave}"/>
<apex:commandButton value="Cancel" action="{!cancel}"/>
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!STGPR}" var="a" id="table">
<apex:pageBlockSection title="Information" columns="2">
<apex:outputField value="{!a.Account_Name__c}"/>
<apex:pageBlockSectionItem />
<apex:outputField value="{!a.Name}"/>
<apex:inputField value="{!a.Quantity__c}" required="true"/>
<apex:outputField value="{!a.STG_Promotion__c}"/>
<apex:outputField value="{!a.Payment_Amount__c}"/>
<apex:outputField value="{!a.Lane_Vendor_Number__c}"/>
<apex:inputField value="{!a.Reference_for_remittance__c}" required="false"/>
<apex:outputField value="{!a.Promoted_Brand__c}"/>
<apex:pageBlockSectionItem />
<apex:outputField value="{!a.Promotion_Type__c}"/>
<apex:pageBlockSectionItem />
<apex:outputField value="{!a.Promotional_Rate__c}"/>
<apex:inputField value="{!a.Comments__c}" required="false"/>
<apex:pageBlockSectionItem />
<apex:inputField value="{!a.Manager_Approved__c}" required="false"/>
<apex:pageBlockSectionItem />
<apex:inputField value="{!a.Senior_Manager_Approved__c}" required="false"/>
<apex:pageBlockSectionItem />
<apex:inputField value="{!a.Director_Approved__c}" required="false"/>
<apex:pageBlockSectionItem />
<apex:inputField value="{!a.File_Attached_to_Payment_Request__c}" required="false"/>
<apex:pageBlockSectionItem />
<apex:inputField value="{!a.Paid__c}" required="false"/>
<apex:pageBlockSectionItem />
<apex:OutputField value="{!a.Paid_Date__c}"/>
</apex:pageBlockSection>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Apex Class -
public class ContentNewSTGPR {
public ContentNewSTGPR(ApexPages.StandardController controller) {
}
public List<STG_Payment_Requests__c> STGPR {get; set;}
public ContentNewSTGPR(){
STGPR = new List<STG_Payment_Requests__c>();
STGPR.add(new STG_Payment_Requests__c());
}
public void addrow(){
STGPR.add(new STG_Payment_Requests__c());
}
public PageReference save(){
insert STGPR;
PageReference home = new PageReference('/home/home.jsp');
home.setRedirect(true);
return home;
}
}
Update class in following manner.
public class ContentNewSTGPR
{
public List<STG_Payment_Requests__c> STGPR
{
get
{
if(STGPR == null)
return STGPR = New List<STG_Payment_Requests__c>();
else
return STGPR;
}set;
}
public ContentNewSTGPR(ApexPages.StandardController controller)
{
STG_Payment_Requests__c objSTG_Payment_Requests = (Account)stdController.getRecord();
STGPR.add(objSTG_Payment_Requests);
}
public void addrow(){
STGPR.add(new STG_Payment_Requests__c());
}
public PageReference save()
{
insert STGPR;
PageReference home = new PageReference('/home/home.jsp');
home.setRedirect(true);
return home;
}
}
Thank you
Niks
Nik,
Thanks for the quick response!! However, I am getting an error when I compile - Error: Compile Error: Variable does not exist: stdController - on this line
STG_Payment_Requests__c objSTG_Payment_Requests = (Account)stdController.getRecord();
Should this be referencing Account?
Thanks,
Andrew
Its a variable name for ApexPages.StandardController. You have named it 'controller'.
please use:
STG_Payment_Requests__c objSTG_Payment_Requests = (Account)controller.getRecord();
Sorry Its my Bad,
STG_Payment_Requests__c objSTG_Payment_Requests = (STG_Payment_Requests__c )controller.getRecord();
Thank you
Niks
Thanks again, now it compiles. But now i am back to the same initial issue; all that displays are the buttons at the top and bottom of the page, no fields. I am not getting a new record created.
Sorry if this seems so basic to you, I am trying to learn this programming on the fly and this is my first attempt to create a new record.
Andrew
Can you put <apex:message/> tag in your page to see if you are getting any error?
You should also debug the collection you are trying to show on a page... Obvious reason is that your collection {!STGPR} is null.
Sorry for the long delay in getting back to this issue.
Here is the current code and the debug log.
Page:
<apex:page standardController="STG_Payment_Requests__c" extensions="ContentNewSTGPR">
<apex:sectionHeader title="STG Payment Request" subtitle="{!STG_Payment_Requests__c.name}"/>
<apex:message />
<apex:form >
<apex:pageBlock title="New STG Payment Request">
<apex:pageBlockButtons location="top">
<apex:commandButton value="Save" action="{!save}"/>
<apex:commandButton value="Update" action="{!quicksave}"/>
<apex:commandButton value="Cancel" action="{!cancel}"/>
</apex:pageBlockButtons>
<apex:pageBlockButtons location="bottom">
<apex:commandButton value="Save" action="{!save}"/>
<apex:commandButton value="Update" action="{!quicksave}"/>
<apex:commandButton value="Cancel" action="{!cancel}"/>
</apex:pageBlockButtons>
<apex:message/>
<apex:pageBlockTable value="{!STGPR}" var="a" id="table">
<apex:pageBlockSection title="Information" columns="2">
<apex:outputField value="{!a.Account_Name__c}"/>
<apex:pageBlockSectionItem />
<apex:outputField value="{!a.Name}"/>
<apex:inputField value="{!a.Quantity__c}" required="true"/>
<apex:outputField value="{!a.STG_Promotion__c}"/>
<apex:outputField value="{!a.Payment_Amount__c}"/>
<apex:outputField value="{!a.Lane_Vendor_Number__c}"/>
<apex:inputField value="{!a.Reference_for_remittance__c}" required="false"/>
<apex:outputField value="{!a.Promoted_Brand__c}"/>
<apex:pageBlockSectionItem />
<apex:outputField value="{!a.Promotion_Type__c}"/>
<apex:pageBlockSectionItem />
<apex:outputField value="{!a.Promotional_Rate__c}"/>
<apex:inputField value="{!a.Comments__c}" required="false"/>
<apex:pageBlockSectionItem />
<apex:inputField value="{!a.Manager_Approved__c}" required="false"/>
<apex:pageBlockSectionItem />
<apex:inputField value="{!a.Senior_Manager_Approved__c}" required="false"/>
<apex:pageBlockSectionItem />
<apex:inputField value="{!a.Director_Approved__c}" required="false"/>
<apex:pageBlockSectionItem />
<apex:inputField value="{!a.File_Attached_to_Payment_Request__c}" required="false"/>
<apex:pageBlockSectionItem />
<apex:inputField value="{!a.Paid__c}" required="false"/>
<apex:pageBlockSectionItem />
<apex:OutputField value="{!a.Paid_Date__c}"/>
</apex:pageBlockSection>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Class:
public class ContentNewSTGPR {
public List<STG_Payment_Requests__c> STGPR {
get {
System.debug('======11111=======>'+STGPR);
if(STGPR == null)
return STGPR = New List<STG_Payment_Requests__c>();
else
System.debug('=====22222=========>'+STGPR);
return STGPR;
} set;
}
public ContentNewSTGPR(ApexPages.StandardController controller) {
STG_Payment_Requests__c objSTG_Payment_Requests = (STG_Payment_Requests__c )controller.getRecord();
STGPR.add(objSTG_Payment_Requests);
System.debug('=======33333=======>'+STGPR);
}
public void addrow(){
STGPR.add(new STG_Payment_Requests__c());
}
public PageReference save() {
insert STGPR;
PageReference home = new PageReference('/home/home.jsp');
home.setRedirect(true);
return home;
}
}
Debug Log:
It is showing that STGPR is getting popluated -
But the display is still only the buttons, no data
Thanks for your help!