function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Avula ReddyAvula Reddy 

Should reoccur the same fields on clicking 'ADD' button on the same record page

Hi,

I want the fields in the record page to be repeated in the same page on clicking the 'Add' button. Once clicked on save all the added field values should be displayed.

Below is what I need. Once I clicked on 'Add New ItemRequest', the fields should be repeated below to the existing one and once clicked on Save, all the requests should be saved under singlr Item Request Name.

User-added image

RR
Valerijs ProkudinsValerijs Prokudins
I would do this by creating a list of Item_Request__c objects and displaying it by apex:repeat tag. Once I click "add" the new record Item_Request__c record should be created and added to che list, then pageblock containing apex:repeat tag should be rerendered to show newly created record. Once Save button is pressed the whole list should be updated with the new values(added by the user in the page) and written to the database.
Avula ReddyAvula Reddy
Hi Valerijs,

i've achieved the field sets repeating by by placing the fields in field set and using <apex:repeat> tag but each time when I click the 'Add New ItemRequest' button I want it the method to be invoked and display the fields again....

I thing I'm missing a for loop in method to keep rendering the pageblock. Can you please help in achieving it?

Below isthe code.

<apex:page standardController="Item_Request__c" extensions="NewitemRequest">
    <apex:form >
        <apex:pageBlock rendered="{!show}">
                <apex:pageBlockSection title="New item request">
                   
                    <apex:inputField value="{!Item_Request__c.Item_Code__c}"/>
                    <apex:inputField value="{!Item_Request__c.Priority__c}"/>
                    <apex:inputField value="{!Item_Request__c.Quantity__c}"/>
                    <apex:inputField value="{!Item_Request__c.Status__c}"/>
                    <apex:inputField value="{!Item_Request__c.Business_Justification__c}"/>
                </apex:pageBlockSection>
            <apex:pageBlockButtons location="bottom">
                <apex:commandButton value="Add new Item Req" action="{!showfields}">             
                </apex:commandButton>
            </apex:pageBlockButtons>
        </apex:pageBlock>
       
      <apex:pageblock rendered="{!hide}" >
        <apex:pageBlockSection>
        <apex:repeat value="{!$Objecttype.Item_Request__c.fieldsets.AddNewItemRequest}" var="ir">
        <apex:inputField value="{!Item_Request__c[ir]}"/>     
        </apex:repeat>  
        </apex:pageBlockSection>
       <apex:pageBlockButtons location="bottom">
                <apex:commandButton value="Add new Item Req" action="{!showfields}"/>
                <apex:commandButton value="Save" action="{!save}"/>
                
            </apex:pageBlockButtons>
      </apex:pageblock>
           
    </apex:form>
</apex:page>

Controller:
---------------
public class NewitemRequest {
    public boolean show{get;set;}
    public boolean hide{get;set;}      
    public NewitemRequest(ApexPages.StandardController controller) {
        show=true;
        hide=false;
    }
    public void showfields()
    {
        show=true;
        hide=true;
       
    }
}
Valerijs ProkudinsValerijs Prokudins
Sorry, today I won't make it, will go home ina  moment. I will help you on Monday. have a good weekend :)
VPROKVPROK
Had time to make some investigation :) Very raw and buggy, but you can play with this and this will give you a way how to implement this. At least I hope so :)
NB: new line won't be added until you will fill in the name(required field for account)
Class:
public with sharing class devBoardMultiAdd {
public list<Account> accounts{get;set;}


public devBoardMultiAdd(ApexPages.StandardController stdController){
accounts = new list<Account>();
accounts.add(new Account(Name=''));
accounts.add(new Account(Name=''));
	system.debug('mydebug');
	system.debug(accounts);
}

public pageReference addFields(){
	system.debug('mydebugadd fields');
	accounts.add(new Account(Name=''));
	system.debug('mydebugadd fields');
	system.debug(accounts);
	return null;
}



public pageReference saveAccs(){
	insert(accounts);
	return null;
}




}

VF:
<apex:page standardController="Account" extensions="devBoardMultiAdd">
    <apex:form >
        <apex:pageBlock id="theForm">
                <apex:pageBlockSection title="New item request">
          <apex:repeat value="{!accounts}" var="acc" id="theRepeat">
		
	
        <apex:inputField value="{!acc.Name}" /><br/>

    </apex:repeat>             
                    

                </apex:pageBlockSection>
            <apex:pageBlockButtons location="bottom">
                <apex:commandButton value="Add new Item Req" action="{!addfields}" rerender="theForm">
                <apex:commandButton value="Save" action="{!saveAccs}" />                 
                </apex:commandButton>
            </apex:pageBlockButtons>
        </apex:pageBlock>
        
        
        


           
    </apex:form>
</apex:page>

Valerijs