You need to sign in to do that
Don't have an account?
UI desing
Hi all,
I need a help to create a UI page,requirement is somewhat like
when user open the same page it should have all customername,productname filled already and able to fill the forecast qty below the months for jan,feb,mar........dec.finally click the save button to save all records at once in table having fields
Customername,productname,month,forecastqty with their respective values.
i have designed the page and able to enter the forecast qty also below the months but my problem is this that i cant save all the data at one time..... my UI code and page display is below
<apex:page standardController="Forecast_Entry__c" extensions="ForecastEntryExtension" > <apex:form > <h1>Sales Forecast</h1> <apex:pageBlock > <apex:pageBlockSection title="Forecast Records"> <div> <apex:dataTable value="{!ForecastRecords}" var="fc" styleClass="list"> <apex:column > <apex:facet name="header">Customer Name</apex:facet> <apex:inputField value="{!fc.Customer_Name__c}"/> </apex:column> <apex:column > <apex:facet name="header">Item Name</apex:facet> <apex:inputfield value="{!fc.Item_Name__c}"/> </apex:column> <apex:column > <apex:facet name="header"> <div align="center"> Month1 </div> </apex:facet> <input maxlength="80" name="sbstr" size="3" type="text" value="" /> </apex:column> <apex:column > <apex:facet name="header"> <div align="center"> Month2 </div> </apex:facet> <input maxlength="80" name="sbstr" size="3" type="text" value="" /> </apex:column> <apex:column > <apex:facet name="header"> <div align="center"> Month3 </div> </apex:facet> <input maxlength="80" name="sbstr" size="3" type="text" value="" /> </apex:column> <apex:column > <apex:facet name="header"><div align="center"> Month4 </div> </apex:facet> <input maxlength="80" name="sbstr" size="3" type="text" value="" /> </apex:column> <apex:column > <apex:facet name="header"><div align="center"> Month5 </div> </apex:facet> <input maxlength="80" name="sbstr" size="3" type="text" value="" /> </apex:column> <apex:column > <apex:facet name="header"><div align="center"> Month6 </div> </apex:facet> <input maxlength="80" name="sbstr" size="3" type="text" value="" /> </apex:column> <apex:column > <apex:facet name="header"><div align="center"> Month7 </div> </apex:facet> <input maxlength="80" name="sbstr" size="3" type="text" value="" /> </apex:column> <apex:column > <apex:facet name="header"><div align="center"> Month8 </div> </apex:facet> <input maxlength="80" name="sbstr" size="3" type="text" value="" /> </apex:column> <apex:column > <apex:facet name="header"><div align="center"> Month9 </div> </apex:facet> <input maxlength="80" name="sbstr" size="3" type="text" value="" /> </apex:column> <apex:column > <apex:facet name="header"><div align="center"> Month10 </div> </apex:facet> <input maxlength="80" name="sbstr" size="3" type="text" value="" /> </apex:column> <apex:column > <apex:facet name="header"><div align="center"> Month11 </div> </apex:facet> <input maxlength="80" name="sbstr" size="3" type="text" value="" /> </apex:column> <apex:column > <apex:facet name="header"><div align="center"> Month12 </div> </apex:facet> <input maxlength="80" name="sbstr" size="3" type="text" value="" /> </apex:column> </apex:datatable> </div> <div> <td align="right"> <input value=" Save " class="btn" name="save" title="Save" type="submit" /> <input value=" Cancel " class="btn" name="Cancel" title="Cancel" type="submit" /> </td> </div> </apex:pageBlockSection> </apex:pageBlock> <apex:detail ></apex:detail> <apex:detail subject="{!Forecast_Entry__c.Customer_Name__c}" relatedList="false" /> </apex:form> </apex:page>
Customer Product Jan Feb Mar Apr ........................ Dec
abc xyz 100 90 20
abc pqr 30 20
mno xyz 40
Save Cancel
Is there any such control available already by salesforce?? if not how to save data at once from my this page?
All is i need a save functionality code.
any help will be greatly appreciated... Please help me out in terms of code....
Thanks,
Jha
hi,
My controller code is below:-
public with sharing class ForecastEntryExtension { private final Forecast_entry__c forecastentryObj; public ForecastEntryExtension(ApexPages.StandardController controller) { this.forecastentryObj = (forecast_entry__c)controller.getrecord(); } private List<forecast_entry__c> forecasts; public List<forecast_entry__c> getForecasts() { forecasts =[SELECT a.Customer_name__c,a.item_name__c, a.month__c,a.forecast_qty__c,a.contact__c FROM forecast_entry__c a ]; return forecasts; } public forecast_entry__c[] getForecastRecords() { /* forecastentryList =[SELECT a.Customer_name__c,a.item_name__c,a.month__c,a.forecast_qty__c, b.Customer_name__c,c.Item_name__c FROM forecast_entry__c a,customer_entry__c b, item_entry__c where a.Customer_name__c= b.Customer_name__c and a.item_name__c=c.Item_name__c ]; */ Forecast_entry__c[] forecastentryList =[SELECT a.Customer_name__c,a.item_name__c, a.month__c,a.forecast_qty__c,a.contact__c FROM forecast_entry__c a ]; return forecastentryList; } // # To Test Save public void getSaveData() { forecast_entry__c testforecast = new forecast_entry__c(item_name__c='a0590000000BgRRAA0',forecast_qty__c=202020 ); insert testforecast ; // # To Test Update } Public void getUpdateData(){ update forecasts; } }
is it possible to get value from my UI to controller and save accordingly?if so please share the code...
All is to fill the forecastqty monthwise through my UI page and save all data at once.
Thanks,
jha
Hi Jha, How about you go about writing yout own save method and then add a couple of insert statements to insert data?
well.i have created my save function but not able to pass values frommy UI page to controlpage where my save method resides.
All i want to pass value from UI to control,so dat it can we executed.
Note :
im using <apex:inputtext value="{!fc.Forecast_Qty__c}" rendered="{!fc.Month__c='Month1'}" />
not <apex:inputfield value="{!fc.Forecast_Qty__c}" rendered="{!fc.Month__c='Month1'}" />
so binding is not working in this case.
Thanks,
Jha
I checked your code and you can achieve the same by using wrapper class.
Also attached the code.
public List<foreCastWrapper> getForecastRecords() {
List<foreCastWrapper> fcwrapperList = new List<foreCastWrapper> ();
for(Forecast_entry__c fc : [SELECT a.Customer_name__c,a.item_name__c,
a.month__c,a.forecast_qty__c,a.contact__c FROM forecast_entry__c a ]) {
fcwrapperList.add(new foreCastWrapper(fc));
}
return fcwrapperList;
}
class foreCastWrapper {
public forecast_entry__c fc {get; set;}
public String month1 {get; set;}
public String month2 {get; set;}
public String month3 {get; set;}
public String month4 {get; set;}
public String month5 {get; set;}
public String month6 {get; set;}
public String month7 {get; set;}
public String month8 {get; set;}
public String month9 {get; set;}
public String month10 {get; set;}
public String month11 {get; set;}
public String month12 {get; set;}
public foreCastWrapper(forecast_entry__c fc) {
this.fc = fc;
}
}
Also you need to make changes in pagelayout. e.g.
<input maxlength="80" name="sbstr" size="3" type="text" value="{!fc.month1}" />
Hi,
I realy appreciate your help but my bad that wen i press save it goes without error but my data not getting saved.
can u please give your complete code. i think there must be something wrong. im using below code
<apex:commandButton Value="Save" action="{!getUpdateData}" />
Public void getUpdateData(){
update forecasts;
}
Do i need to code for update method.
Thanks & Regards,
Jha
Hi,
My complete code is below
public with sharing class ForecastEntryExtension { private final Forecast_entry__c forecastentryObj; public ForecastEntryExtension(ApexPages.StandardController controller) { this.forecastentryObj = (forecast_entry__c)controller.getrecord(); } private List<forecast_entry__c> forecasts; public string SelectedRecordId { get; set; } public List<forecast_entry__c> getForecasts() { forecasts =[SELECT a.Customer_name__c,a.item_name__c, a.month__c,a.forecast_qty__c,a.contact__c FROM forecast_entry__c a ]; return forecasts; } public forecast_entry__c[] getForecastRecordss() { /* forecastentryList =[SELECT a.Customer_name__c,a.item_name__c,a.month__c,a.forecast_qty__c, b.Customer_name__c,c.Item_name__c FROM forecast_entry__c a,customer_entry__c b, item_entry__c where a.Customer_name__c= b.Customer_name__c and a.item_name__c=c.Item_name__c ]; */ Forecast_entry__c[] forecastentryList =[SELECT a.Customer_name__c,a.item_name__c, a.month__c,a.forecast_qty__c,a.contact__c FROM forecast_entry__c a ]; return forecastentryList; } public void getSaveData() { forecast_entry__c testforecast = new forecast_entry__c(item_name__c='a0590000000BgRRAA0',forecast_qty__c=202020 ); insert testforecast ; } Public void getUpdateData(){ update forecasts; } //-------------------------------------------- public List<foreCastWrapper> getForecastRecords() { List<foreCastWrapper> fcwrapperList = new List<foreCastWrapper> (); for(Forecast_entry__c fc : [SELECT a.Customer_name__c,a.item_name__c,a.month__c,a.forecast_qty__c,a.contact__c FROM forecast_entry__c a ]) { fcwrapperList.add(new foreCastWrapper(fc)); } return fcwrapperList; } class foreCastWrapper { public forecast_entry__c fc {get; set;} public String month1 {get; set;} public String month2 {get; set;} public String month3 {get; set;} public String month4 {get; set;} public String month5 {get; set;} public String month6 {get; set;} public String month7 {get; set;} public String month8 {get; set;} public String month9 {get; set;} public String month10 {get; set;} public String month11 {get; set;} public String month12 {get; set;} public foreCastWrapper(forecast_entry__c fc) { this.fc = fc; } } //---------------------------------------------- }
<apex:page standardController="Forecast_Entry__c" extensions="ForecastEntryExtension" > <apex:form > <apex:pageBlock title="Forecast Entry Form"> <apex:pagemessages /> <apex:pageblockButtons > <apex:commandButton Value="Save" action="{!getUpdateData}" /> <apex:commandButton value="Cancel"/> </apex:pageblockButtons> <apex:pageblockSection > <!-- <apex:dataTable value="{!ForecastRecords}" var="fc" styleClass="list"> --> <apex:dataTable value="{!ForecastRecords}" var="fcc" styleClass="list"> <apex:column > <apex:facet name="header">Customer Name</apex:facet> <apex:inputfield value="{!fcc.fc.Customer_Name__c}"/> </apex:column> <apex:column > <apex:facet name="header">Item Name</apex:facet> <apex:inputfield value="{!fcc.fc.Item_Name__c}"/> </apex:column> <apex:column > <apex:facet name="header"> <div align="center"> Month1 </div> </apex:facet> <input maxlength="80" name="sbstr" size="3" type="text" value="{!fcc.month1}" /> </apex:column> <apex:column > <apex:facet name="header"> <div align="center"> Month2 </div> </apex:facet> <input maxlength="80" name="sbstr" size="3" type="text" value=""/> </apex:column> <apex:column > <apex:facet name="header"> <div align="center"> Month3 </div> </apex:facet> <input maxlength="80" name="sbstr" size="3" type="text" value="" /> </apex:column> <apex:column > <apex:facet name="header"><div align="center"> Month4 </div> </apex:facet> <input maxlength="80" name="sbstr" size="3" type="text" value="" /> </apex:column> <apex:column > <apex:facet name="header"><div align="center"> Month5 </div> </apex:facet> <input maxlength="80" name="sbstr" size="3" type="text" value="" /> </apex:column> <apex:column > <apex:facet name="header"><div align="center"> Month6 </div> </apex:facet> <input maxlength="80" name="sbstr" size="3" type="text" value="" /> </apex:column> <apex:column > <apex:facet name="header"><div align="center"> Month7 </div> </apex:facet> <input maxlength="80" name="sbstr" size="3" type="text" value="" /> </apex:column> <apex:column > <apex:facet name="header"><div align="center"> Month8 </div> </apex:facet> <input maxlength="80" name="sbstr" size="3" type="text" value="" /> </apex:column> <apex:column > <apex:facet name="header"><div align="center"> Month9 </div> </apex:facet> <input maxlength="80" name="sbstr" size="3" type="text" value="" /> </apex:column> <apex:column > <apex:facet name="header"><div align="center"> Month10 </div> </apex:facet> <input maxlength="80" name="sbstr" size="3" type="text" value="" /> </apex:column> <apex:column > <apex:facet name="header"><div align="center"> Month11 </div> </apex:facet> <input maxlength="80" name="sbstr" size="3" type="text" value="" /> </apex:column> <apex:column > <apex:facet name="header"><div align="center"> Month12 </div> </apex:facet> <input maxlength="80" name="sbstr" size="3" type="text" value="" /> </apex:column> </apex:datatable> </apex:pageblockSection> </apex:pageBlock> </apex:form> </apex:page>
Thanks,
Jha
Im getting error :
System.NullPointerException: Attempt to de-reference a null object
Class.TestEntryExtension.getUpdateData: line 49, column 12 External entry point
Please ignore my previous code consider new below
public with sharing class TestEntryExtension { public TestEntryExtension(ApexPages.StandardController controller) { } private List<forecast_entry__c> forecasts; private List<forecast_entry__c> fcwrapperList; public List<foreCastWrapper> getForecastRecords() { List<foreCastWrapper> fcwrapperList = new List<foreCastWrapper> (); for(Forecast_entry__c fc : [SELECT a.Customer_name__c,a.item_name__c,a.month__c,a.forecast_qty__c,a.contact__c FROM forecast_entry__c a ]) { fcwrapperList.add(new foreCastWrapper(fc)); } return fcwrapperList;}class foreCastWrapper { public forecast_entry__c fc {get; set;} public String month1 {get; set;} public String month2 {get; set;} public String month3 {get; set;} public String month4 {get; set;} public String month5 {get; set;} public String month6 {get; set;} public String month7 {get; set;} public String month8 {get; set;} public String month9 {get; set;} public String month10 {get; set;} public String month11 {get; set;} public String month12 {get; set;} public foreCastWrapper(forecast_entry__c fc) { this.fc = fc; } } public List<forecast_entry__c> getForecasts() { forecasts =[SELECT a.Customer_name__c,a.item_name__c, a.month__c,a.forecast_qty__c,a.contact__c FROM forecast_entry__c a ]; return forecasts; } Public pagereference getUpdateData(){ update fcwrapperList; return null; } Public void getUpdateData1(){ update forecasts; } }
<apex:page standardController="Forecast_Entry__c" extensions="TestEntryExtension" > <apex:form > <apex:pageBlock title="Forecast Entry Form"> <apex:pagemessages /> <apex:pageblockButtons > <apex:commandButton Value="Save" action="{!getUpdateData}" /> <apex:commandButton value="Cancel"/> </apex:pageblockButtons> <apex:pageblockSection > <!-- <apex:dataTable value="{!ForecastRecords}" var="fc" styleClass="list"> --> <apex:dataTable value="{!ForecastRecords}" var="fcc" styleClass="list"> <apex:column > <apex:facet name="header">Customer Name</apex:facet> <apex:inputfield value="{!fcc.fc.Customer_Name__c}" /> </apex:column> <apex:column > <apex:facet name="header">Item Name</apex:facet> <apex:inputfield value="{!fcc.fc.Item_Name__c}"/> </apex:column> <apex:column > <apex:facet name="header"> <div align="center"> Month1 </div> </apex:facet> <input maxlength="80" name="sbstr" size="3" type="text" value="{!fcc.month1}" /> </apex:column> <apex:column > <apex:facet name="header"> <div align="center"> Month2 </div> </apex:facet> <input maxlength="80" name="sbstr" size="3" type="text" value="{!fcc.month2}" /> </apex:column> </apex:datatable> </apex:pageblockSection> </apex:pageBlock> </apex:form> </apex:page>
if im using getUpdateData1() and
<apex:inputfield value="{!fc.Forecast_Qty__c}" rendered="{!fc.Month__c='Month1'}" />
its working fine but there is nothing logical because we are using binding here but wats wrong in above code
case!please help me out.i cant figure it out.
please u r my final hope. so please
Thanks n Regards
Jha
Hi,
Two important thing you need to remember.
1. foreCastWrapper is a wrapper class and it does not exists in database so you cannot insert it into salesforce. I created that wrapper because of your pagelayout requirement.
2. If you want to save all month record individually you need to create that many field in database and remove wrapper class or if you want to store single month record you need to write some business logic before storing the data into database.
Here is the working code. Hope this will help!
public with sharing class ForecastEntryExtension { private final Forecast_entry__c forecastentryObj; private List<forecast_entry__c> forecasts; public ForecastEntryExtension(ApexPages.StandardController controller) { this.forecastentryObj = (forecast_entry__c)controller.getrecord(); } public List<forecast_entry__c> getForecasts() { forecasts =[SELECT a.Customer_name__c,a.item_name__c, a.month__c,a.forecast_qty__c,a.contact__c FROM forecast_entry__c a ]; return forecasts; } public forecast_entry__c[] getForecastRecords() { /* forecastentryList =[SELECT a.Customer_name__c,a.item_name__c,a.month__c,a.forecast_qty__c, b.Customer_name__c,c.Item_name__c FROM forecast_entry__c a,customer_entry__c b, item_entry__c where a.Customer_name__c= b.Customer_name__c and a.item_name__c=c.Item_name__c ]; */ Forecast_entry__c[] forecastentryList =[SELECT a.Customer_name__c,a.item_name__c, a.month__c,a.forecast_qty__c,a.contact__c FROM forecast_entry__c a ]; return forecastentryList; } // # To Test Save public PageReference save() { forecast_entry__c testforecast = new forecast_entry__c(item_name__c='a0590000000BgRRAA0',forecast_qty__c='20', Customer_name__c = 'test'); insert testforecast ; return null; // # To Test Update } public void getUpdateData(){ update forecasts; } }
<apex:page standardController="Forecast_entry__c" extensions="ForecastEntryExtension" > <apex:form > <h1>Sales Forecast</h1> <apex:pageBlock > <apex:pageblockButtons > <apex:commandButton value="Save" action="{!save}"/> <apex:commandButton value="Cancel"/> </apex:pageblockButtons> <apex:pageBlockSection title="Forecast Records"> <div> <apex:dataTable value="{!ForecastRecords}" var="fc" styleClass="list"> <apex:column > <apex:facet name="header">Customer Name</apex:facet> <apex:inputField value="{!fc.Customer_name__c}"/> </apex:column> <apex:column > <apex:facet name="header">Item Name</apex:facet> <apex:inputfield value="{!fc.item_name__c}"/> </apex:column> <apex:column > <apex:facet name="header"> <div align="center"> Month1 </div> </apex:facet> <input maxlength="80" name="sbstr" size="3" type="text" value="" /> </apex:column> <apex:column > <apex:facet name="header"> <div align="center"> Month2 </div> </apex:facet> <input maxlength="80" name="sbstr" size="3" type="text" value="" /> </apex:column> <apex:column > <apex:facet name="header"> <div align="center"> Month3 </div> </apex:facet> <input maxlength="80" name="sbstr" size="3" type="text" value="" /> </apex:column> <apex:column > <apex:facet name="header"><div align="center"> Month4 </div> </apex:facet> <input maxlength="80" name="sbstr" size="3" type="text" value="" /> </apex:column> <apex:column > <apex:facet name="header"><div align="center"> Month5 </div> </apex:facet> <input maxlength="80" name="sbstr" size="3" type="text" value="" /> </apex:column> <apex:column > <apex:facet name="header"><div align="center"> Month6 </div> </apex:facet> <input maxlength="80" name="sbstr" size="3" type="text" value="" /> </apex:column> <apex:column > <apex:facet name="header"><div align="center"> Month7 </div> </apex:facet> <input maxlength="80" name="sbstr" size="3" type="text" value="" /> </apex:column> <apex:column > <apex:facet name="header"><div align="center"> Month8 </div> </apex:facet> <input maxlength="80" name="sbstr" size="3" type="text" value="" /> </apex:column> <apex:column > <apex:facet name="header"><div align="center"> Month9 </div> </apex:facet> <input maxlength="80" name="sbstr" size="3" type="text" value="" /> </apex:column> <apex:column > <apex:facet name="header"><div align="center"> Month10 </div> </apex:facet> <input maxlength="80" name="sbstr" size="3" type="text" value="" /> </apex:column> <apex:column > <apex:facet name="header"><div align="center"> Month11 </div> </apex:facet> <input maxlength="80" name="sbstr" size="3" type="text" value="" /> </apex:column> <apex:column > <apex:facet name="header"><div align="center"> Month12 </div> </apex:facet> <input maxlength="80" name="sbstr" size="3" type="text" value="" /> </apex:column> </apex:datatable> </div> </apex:pageBlockSection> </apex:pageBlock> <apex:detail ></apex:detail> <apex:detail subject="{!Forecast_entry__c.Customer_name__c}" relatedList="false" /> </apex:form> </apex:page>
i need that page layout only.but i have only customer,product,month and forecast qty in table,so need to fill that way. means if user enter below month1 30 means my data goes like
customer abc
product xyz
Month month1
qty 30
if he enters below month1 30 and month5 200 then this case there should be two entry in database
customer abc
product xyz
Month month1
qty 30
customer abc
product xyz
Month month5
qty 200
actually the thing is
i want a UI where customer and product is coming from their masters and there should be month from jan to dec.
user just enter the forecast qty for any number of months for any customer and products.
press save and data should be saved. this much only. but the UI should be lke
customer product jan feb mar apr may ------------- dec
abc def
mno rst
pqr tqr
save cancel
can u plz suggest how will u do this, wat will the database field and logic to save.
Thanks and regards,
JHa
Try this.
private List<forecast_entry__c> forecasts;
private List<foreCastWrapper> fcwrapperList;
public PageReference save() {
List<forecast_entry__c> fclist = new List<forecast_entry__c> ();
forecast_entry__c fctemp;
for(fcwrapperList fcw : fcwrapperList) {
if(fcw.month1 != null) {
fctemp = fcw.fc;
fctemp.month__c = 'month1';
fctemp.forecast_qty__c = fcw.month1;
fclist.add(fctemp);
}
//same for all
}
insert fclist; return null;
}
Im sorry.can u please send me complete control and UI code because its missing something.
Rly thanks for your evrything.
Thanks & Regards,
Jha