+ Start a Discussion
Mr. MetMr. Met 

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;
}
}

Niket SFNiket SF

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

Mr. MetMr. Met

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

Sandeep001Sandeep001

Its a variable name for ApexPages.StandardController. You have named it 'controller'.

 

please use:

 

STG_Payment_Requests__c objSTG_Payment_Requests = (Account)controller.getRecord();

 

 

Niket SFNiket SF

Sorry Its my Bad,

 

STG_Payment_Requests__c objSTG_Payment_Requests = (STG_Payment_Requests__c )controller.getRecord();

 

Thank you

Niks

Mr. MetMr. Met

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

Sandeep001Sandeep001

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.

Niket SFNiket SF
Try to insert only one record to check that code is working or not. Please add debug statement to check the code execution process.
Mr. MetMr. Met

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:

28.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WORKFLOW,INFO
08:55:02.147 (147761000)|EXECUTION_STARTED
08:55:02.147 (147808000)|CODE_UNIT_STARTED|[EXTERNAL]|066M000000050k9|VF: /apex/NewSTGPaymentRequest
08:55:02.151 (151213000)|CODE_UNIT_STARTED|[EXTERNAL]|01pM0000000A06G|ContentNewSTGPR <init>
08:55:02.151 (151229000)|SYSTEM_MODE_ENTER|true
08:55:02.152 (152126000)|METHOD_ENTRY|[1]|01pM0000000A06G|ContentNewSTGPR.ContentNewSTGPR()
08:55:02.152 (152144000)|METHOD_EXIT|[1]|ContentNewSTGPR
08:55:02.152 (152218000)|SYSTEM_METHOD_ENTRY|[15]|ApexPages.StandardController.getRecord()
08:55:02.152 (152425000)|SYSTEM_METHOD_EXIT|[15]|ApexPages.StandardController.getRecord()
08:55:02.152 (152447000)|METHOD_ENTRY|[16]|01pM0000000A06G|ContentNewSTGPR.__sfdc_STGPR()
08:55:02.152 (152578000)|SYSTEM_METHOD_ENTRY|[4]|String.valueOf(Object)
08:55:02.152 (152603000)|SYSTEM_METHOD_EXIT|[4]|String.valueOf(Object)
08:55:02.152 (152626000)|SYSTEM_METHOD_ENTRY|[4]|System.debug(ANY)
08:55:02.152 (152640000)|USER_DEBUG|[4]|DEBUG|======11111=======>null
08:55:02.152 (152645000)|SYSTEM_METHOD_EXIT|[4]|System.debug(ANY)
08:55:02.152 (152710000)|SYSTEM_CONSTRUCTOR_ENTRY|[6]|<init>()
08:55:02.152 (152742000)|SYSTEM_CONSTRUCTOR_EXIT|[6]|<init>()
08:55:02.152 (152758000)|METHOD_ENTRY|[6]|01pM0000000A06G|ContentNewSTGPR.__sfdc_STGPR(LIST<STG_Payment_Requests__c>)
08:55:02.152 (152770000)|METHOD_EXIT|[6]|01pM0000000A06G|ContentNewSTGPR.__sfdc_STGPR(LIST<STG_Payment_Requests__c>)
08:55:02.152 (152776000)|METHOD_EXIT|[16]|01pM0000000A06G|ContentNewSTGPR.__sfdc_STGPR()
08:55:02.152 (152801000)|SYSTEM_METHOD_ENTRY|[16]|LIST<STG_Payment_Requests__c>.add(Object)
08:55:02.152 (152815000)|SYSTEM_METHOD_EXIT|[16]|LIST<STG_Payment_Requests__c>.add(Object)
08:55:02.152 (152828000)|METHOD_ENTRY|[17]|01pM0000000A06G|ContentNewSTGPR.__sfdc_STGPR()
08:55:02.152 (152883000)|SYSTEM_METHOD_ENTRY|[4]|String.valueOf(Object)
08:55:02.152 (152934000)|SYSTEM_METHOD_EXIT|[4]|String.valueOf(Object)
08:55:02.152 (152945000)|SYSTEM_METHOD_ENTRY|[4]|System.debug(ANY)
08:55:02.152 (152954000)|USER_DEBUG|[4]|DEBUG|======11111=======>(STG_Payment_Requests__c:{STG_Promotion__c=a0VM00000070nMz})
08:55:02.152 (152959000)|SYSTEM_METHOD_EXIT|[4]|System.debug(ANY)
08:55:02.152 (152981000)|SYSTEM_METHOD_ENTRY|[8]|String.valueOf(Object)
08:55:02.153 (153029000)|SYSTEM_METHOD_EXIT|[8]|String.valueOf(Object)
08:55:02.153 (153042000)|SYSTEM_METHOD_ENTRY|[8]|System.debug(ANY)
08:55:02.153 (153051000)|USER_DEBUG|[8]|DEBUG|=====22222=========>(STG_Payment_Requests__c:{STG_Promotion__c=a0VM00000070nMz})
08:55:02.153 (153057000)|SYSTEM_METHOD_EXIT|[8]|System.debug(ANY)
08:55:02.153 (153066000)|METHOD_EXIT|[17]|01pM0000000A06G|ContentNewSTGPR.__sfdc_STGPR()
08:55:02.153 (153077000)|SYSTEM_METHOD_ENTRY|[17]|String.valueOf(Object)
08:55:02.153 (153109000)|SYSTEM_METHOD_EXIT|[17]|String.valueOf(Object)
08:55:02.153 (153120000)|SYSTEM_METHOD_ENTRY|[17]|System.debug(ANY)
08:55:02.153 (153128000)|USER_DEBUG|[17]|DEBUG|=======33333=======>(STG_Payment_Requests__c:{STG_Promotion__c=a0VM00000070nMz})
08:55:02.153 (153134000)|SYSTEM_METHOD_EXIT|[17]|System.debug(ANY)
08:55:02.153 (153151000)|CODE_UNIT_FINISHED|ContentNewSTGPR <init>
08:55:02.153 (153211000)|CODE_UNIT_STARTED|[EXTERNAL]|01pM0000000A06G|ContentNewSTGPR get(STGPR)
08:55:02.153 (153222000)|SYSTEM_MODE_ENTER|true
08:55:02.153 (153240000)|CODE_UNIT_STARTED|[EXTERNAL]|01pM0000000A06G|STGPR
08:55:02.153 (153312000)|SYSTEM_METHOD_ENTRY|[4]|String.valueOf(Object)
08:55:02.153 (153352000)|SYSTEM_METHOD_EXIT|[4]|String.valueOf(Object)
08:55:02.153 (153362000)|SYSTEM_METHOD_ENTRY|[4]|System.debug(ANY)
08:55:02.153 (153370000)|USER_DEBUG|[4]|DEBUG|======11111=======>(STG_Payment_Requests__c:{STG_Promotion__c=a0VM00000070nMz})
08:55:02.153 (153376000)|SYSTEM_METHOD_EXIT|[4]|System.debug(ANY)
08:55:02.153 (153388000)|SYSTEM_METHOD_ENTRY|[8]|String.valueOf(Object)
08:55:02.153 (153418000)|SYSTEM_METHOD_EXIT|[8]|String.valueOf(Object)
08:55:02.153 (153426000)|SYSTEM_METHOD_ENTRY|[8]|System.debug(ANY)
08:55:02.153 (153434000)|USER_DEBUG|[8]|DEBUG|=====22222=========>(STG_Payment_Requests__c:{STG_Promotion__c=a0VM00000070nMz})
08:55:02.153 (153439000)|SYSTEM_METHOD_EXIT|[8]|System.debug(ANY)
08:55:02.153 (153452000)|CODE_UNIT_FINISHED|STGPR
08:55:02.153 (153460000)|CODE_UNIT_FINISHED|ContentNewSTGPR get(STGPR)
08:55:02.271 (271364000)|VF_SERIALIZE_VIEWSTATE_BEGIN|066M000000050k9
08:55:02.273 (273834000)|VF_SERIALIZE_VIEWSTATE_END
08:55:03.025 (276990000)|CUMULATIVE_LIMIT_USAGE
08:55:03.025|LIMIT_USAGE_FOR_NS|(default)|
  Number of SOQL queries: 0 out of 100
  Number of query rows: 0 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 0 out of 150
  Number of DML rows: 0 out of 10000
  Number of code statements: 12 out of 200000
  Maximum CPU time: 0 out of 10000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 10
  Number of Email Invocations: 0 out of 10
  Number of fields describes: 0 out of 100
  Number of record type describes: 0 out of 100
  Number of child relationships describes: 0 out of 100
  Number of picklist describes: 0 out of 100
  Number of future calls: 0 out of 10

08:55:03.025|CUMULATIVE_LIMIT_USAGE_END

08:55:02.277 (277048000)|CODE_UNIT_FINISHED|VF: /apex/NewSTGPaymentRequest
08:55:02.277 (277057000)|EXECUTION_FINISHED

 It is showing that STGPR is getting popluated - 

08:55:02.152 (152954000)|USER_DEBUG|[4]|DEBUG|======11111=======>(STG_Payment_Requests__c:{STG_Promotion__c=a0VM00000070nMz})

 

But the display is still only the buttons, no data

 

Thanks for your help!