+ Start a Discussion
JHAJHA 

Simple custom page save functionatily

I need to pass text box value from UI page to controller to get it save.

  

anyone can please help me out!

 

 

Thanks

Best Answer chosen by Admin (Salesforce Developers) 
sfdcfoxsfdcfox

For lookup fields, I recommend that you simply use a reference to the object directly. Try this:

 

 

// page<apex:page controller="CustomSaveController"> <apex:form> <apex:inputField value="{!myObject.tname__c}" /> <apex:commandButton action="{!doSave}" value="Save" /> </apex:form></apex:page> // Controllerpublic class CustomSaveController{ public testnew1__c myObject { get; set; } public CustomSaveController() { myObject = new testnew1__c(); } public void doSave() { insert myObject; }}

 

In this design, we use an apex inputField, which represents the type of field that the underlying data is bound to (in this case, a lookup field). Coincidentally, this will perform additional rendering (you get the window/popup feature), and we no longer have to manually assign the field to the object; it is taken care of automatically by the object reference. We did have to add a constructor to ensure that memory is allocated to this object before we attempt to use it, but the application logic is reduced in overall complexity.

 

All Answers

sfdcfoxsfdcfox

All you need to do is assign a setter method, and then you can access that UI value from the controller. Generically, it looks like this:

 

 

<!-- page --><apex:page controller="myController"><apex:form><apex:inputText value="{!myField}" /><apex:commandButton action="{!doSave}" value="Save" />

</apex:form>

</apex:page> 

// Controllerpublic class myController { public String myField { get; set; } public void doSave() { myRecordObject record = new myRecordObject(); // replace myRecordObject with object name. record.myField__c = myField; insert record; }}

 

 

 

JHAJHA

Thanks i tried below code but getting 18 digit SF id instead of my actual record,when it viewed!

can u please correct,how to over come this??

 

Thanks again.

 

 

// page <apex:page controller="CustomSaveController"> <apex:form > <apex:inputtext value="{!myField}" /> <apex:commandButton action="{!doSave}" value="Save" /> </apex:form> </apex:page> // Controller public class CustomSaveController{ public String myField { get; set; } public void doSave() { testnew1__c record = new testnew1__c(); record.tname__c = myField; insert record; } }

 

sfdcfoxsfdcfox

For lookup fields, I recommend that you simply use a reference to the object directly. Try this:

 

 

// page<apex:page controller="CustomSaveController"> <apex:form> <apex:inputField value="{!myObject.tname__c}" /> <apex:commandButton action="{!doSave}" value="Save" /> </apex:form></apex:page> // Controllerpublic class CustomSaveController{ public testnew1__c myObject { get; set; } public CustomSaveController() { myObject = new testnew1__c(); } public void doSave() { insert myObject; }}

 

In this design, we use an apex inputField, which represents the type of field that the underlying data is bound to (in this case, a lookup field). Coincidentally, this will perform additional rendering (you get the window/popup feature), and we no longer have to manually assign the field to the object; it is taken care of automatically by the object reference. We did have to add a constructor to ensure that memory is allocated to this object before we attempt to use it, but the application logic is reduced in overall complexity.

 

This was selected as the best answer
JHAJHA

Thanks a lot.it worked.

 

I have one more issue,here it goes like this:
 
I have customer,product master page,to save create customer n product respectively.
 
wat i need to create  UI  in which  all customer relates to all available product   and month from jan to dec.
user will enter the forecast qty for those customer n products below month and click save to save data.
 
say if we hve 2 customer name :-  amit,sumit 
                     3 product    name :-  abc,cde,efg
den on load we should have something lke below
 
Customer      product       jan    feb   mar .....................................................Dec
amit                abc
amit                cde
amit                efg
sumit               abc
sumit               cde
sumit               efg
 
                                Save       Cancel

means something like one cutomer all product combination and data goes into custom object say Customer_Product_Map__C which will have  followings, on save.
1)customer name
2)product name
3)month
4)qty

 

Is it possible here ? Please guide me with some helping source code.Is there any concept of datagrid and dataset like?

 

I will be thankful to you.

 

Message Edited by JHA on 12-28-2009 08:59 PM