You need to sign in to do that
Don't have an account?
Ayush Ujjain
Multiple Input fields from two object on vf page
Hey Guys,
I have a requirement where I have a vf page with multiple input fields from two object and I want to fill the feilds and data will get store to object. i am a bit new to coding,I know we can do this by wrapper class but I have to do this asap. Can some1 pls provide me a demo code kind of stuff asap. Any quick response is highly appreciated.
First two tables is of master object name Capex.Last table is of detail object named item
Required Screensort attached for more details
I have a requirement where I have a vf page with multiple input fields from two object and I want to fill the feilds and data will get store to object. i am a bit new to coding,I know we can do this by wrapper class but I have to do this asap. Can some1 pls provide me a demo code kind of stuff asap. Any quick response is highly appreciated.
First two tables is of master object name Capex.Last table is of detail object named item
Required Screensort attached for more details
Vf:
<apex:page controller="CapexDemoTest">
<apex:Form >
<apex:pageBlock >
<apex:repeat value="{!lstobjfields}" var="a" >
<apex:pageBlockSection >
<tr>
<th>Item Description</th>
<th>Qty</th>
<th>Name of Suppliers</th>
<th>Quoted Price(AED) Unit Price(AED) </th>
<th>Supplier selected </th>
<th>Final Price (AED) </th>
</tr>
<tr>
<td>
<apex:inputField value="{!a.item.Item_Description__c}"/>
</td>
<td>
<apex:inputField value="{!a.item.QTY__c}"/>
</td>
<td>
<apex:inputField value="{!a.item.Name_of_Suppliers__c}"/>
</td>
<td>
<apex:inputField value="{!a.item.Quoted_Price_AED_Unit_Price_AED__c}"/>
</td>
</tr>
</apex:pageBlockSection>
</apex:repeat>
<apex:commandButton Value="save" action="{!saveText}"/>
</apex:pageBlock>
</apex:Form>
</apex:page>
Controller:
public class CapexDemoTest
{
Public String ItemDescription{get;set;}
Public Integer Qty {get;set;}
Public String NameofSuppliers{get;set;}
Public String QuotedPriceAEDUnitPriceAED {get;set;}
Public String Supplierselected {get;set;}
Public String FinalPriceAED {get;set;}
Public Date CAPEXformRequisitionDate{get;set;}
Public String SAPInternalOrder{get;set;}
Public String SAPRequisitionNo {get;set;}
Public Date SAPRequisitionDate {get;set;}
Public String SAPAssetNo {get;set;}
Public String NameofRequestor {get;set;}
Public String CCLocationdescription {get;set;}
Public String CapexOverview {get;set;}
Public String Justification {get;set;}
Public String ApprovedBudget {get;set;}
Public String Utilised{get;set;}
Public String AmountofthisCapex {get;set;}
public List<wrapperclass> lstobjfields {get;set;}
public CapexDemoTest ()
{
lstobjfields = new List<wrapperclass>();
list<Items__c> itemlist= new list <Items__c>();
List<Capex_App__c> caplist= new List<Capex_App__c>();
}
public class wrapperclass // wrapper class to handle multiple objects.
{
public Capex_App__c Cap{get;set;}
public Items__c item {get;set;}
public wrapperclass(Capex_App__c Cap,Items__c item)
{
this.Cap = Cap;
this.item = item;
}
}
public PageReference saveMethod() // this method for inserting records into multiple objects.
{
try
{
List<Capex_App__c> caplist = new List<Capex_App__c>();
List<Items__c> itemlist = new List<Items__c>();
for(wrapperclass wrap : lstobjfields)
{
caplist.add(wrap.Cap);
itemlist.add(wrap.item);
}
if(caplist.add.size() >= 0 && itemlist.size() >= 0)
insert itemlist; // Inserting records in to multiple objects
insert caplist;
}
catch(Exception e)
{
ApexPages.addMessages(e);
}
return ApexPages.currentPage();
}
}