You need to sign in to do that
Don't have an account?

using VF page..how to create userdefined number of records??
Hi,
I am able to create single record for the custom detail object using the VF page, how to define the number of records should get created on VF page itself, so that when i hit save button the defined number of records should get created??
my Apex Class:
public class OrderEntry
{
public List<RR__c> ords {get; set;}
private final Opportunity parOrd;
public OrderEntry(ApexPages.StandardController myController) {
parOrd=(Opportunity)myController.getrecord();
ords = new List<RR__c>();
RR__c LitOrd = new RR__c();
LitOrd.Opportunity__c = parOrd.id;
ords.add(LitOrd);}
public void addrow() {
RR__c LitOrd = new RR__c();
LitOrd.Opportunity__c = parOrd.id;
ords.add(LitOrd);}
public void removerow(){
Integer i = ords.size();
ords.remove(i-1);}
public PageReference save() {
insert ords;
PageReference parrec = new PageReference('/'+ parOrd.id);
parrec.setRedirect(true);
return parrec; }
}
VF Page:
<apex:page standardController="Opportunity" extensions="OrderEntry">
<apex:form >
<apex:pageBlock title="Create Requisitions against Opportunities" >
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}" rerender="error" />
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!ords}" var="a" id="table">
<apex:column headerValue="Opportunity Name">
<apex:inputField value="{!a.Opportunity__c}"/>
</apex:column>
</apex:pageBlockTable>
<apex:pageblockButtons location="bottom">
<div style="text-align:right;margin-right:30px;font-weight:bold;">
<apex:commandLink value="Add Row" action="{!addRow}" rerender="table,error" immediate="true" />
|
<apex:commandLink value="Remove Row" action="{!removeRow}" rerender="table,error" immediate="true" />
</div>
</apex:pageblockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
Ah, so you aren't looking to fill in 5 records on the page, just a single record and then specify how many "instances" of this record to create when saving?
Something along the following lines should do it. Not compiled or tested but should give you the basic idea.
Page:
Controller:
All Answers
Please answer below question
1) Do you want to save predefined no of opportunity record?
2)Will you ask user to provide input for all records if more than one or you will create clone of one record?
Your page/controller looks about right. There's a couple of issues that might bite you:
(1) You have specified the immediate="true" attribute for your buttons - this will discard any changes that the user has made to the opportunity look field for the RR__c records.
(2) You are rerendering a component with an id of "error" for each of your buttons, but I can't see this component in the page.
What behaviour are you seeing? I.e. are you receiving an error or are the records just not being created.
Hi,
I am able to create a single record out of the post i have posted earlier...
The requirement is something like...on the VF itself... i need to enter the value for, number of records i want to create, with the inputs i have given on the VF itself for a particular opportunity...
it will be kind of cloning the records..for ex.
lets say i have 5 inputfields on the VF page includig the "headcount" i.e. number of records to be created inputfield (for example as 5).. then with all the inputs i have entered. 5 records should get created...
Ah, so you aren't looking to fill in 5 records on the page, just a single record and then specify how many "instances" of this record to create when saving?
Something along the following lines should do it. Not compiled or tested but should give you the basic idea.
Page:
Controller:
Hi,
while implementing the same.. i am getting the following error...
NewRequisition Compile Error: Method does not exist or incorrect signature: [LIST<RR__c>].clone(Boolean, Boolean)
Thanks
That implies you have a list of records that you are trying to clone. You shouldn't need to go that route if you are simply capturing a prototype record and cloning that a number of times.