+ Start a Discussion
Mahesh MMahesh M 

Can any one help me this scenario

Hi,
have to dispaly 4 fileds in single row in Opportunity i.e., Opp.Name, Stage, Amount,CloseDate in Opprtunity Edit Page. and Add the " ADD" ,"REMOVE" functionalites in the vf. if i click "ADD " button have to add the one Row( Opp.Name, Stage, Amount,CloseDate).

Thanks & Regards,
Mahesh
Sunil MadanaSunil Madana
Hi Mahesh, 
Below is the code that you asked for.

Apex-Class:
public class OpptyPopup {
    public List<Opportunity> opptyList {get;set;}
    public List<Opportunity> opptyAddList {get;set;}
    public String opptyName {get;set;}   
     
    public OpptyPopup() {
        String sql = 'SELECT Name,StageName,Amount,CloseDate FROM Opportunity';
        opptyList = Database.Query(sql);
        opptyAddList = new List<Opportunity>();
        opptyAddList.add(new Opportunity());
    }
    
    public void AddRow() {
        opptyAddList.add(new Opportunity());
    }  
}
VF-Page:
<apex:page sidebar="false" controller="OpptyPopup">
    <apex:form >
        <apex:pageBlock id="membAdd" >                  
            <apex:pageblockSection >
                <apex:pageBlockTable value="{!opptyAddList}" var="memb">
                    <apex:column headerValue="Opportunity Name">
                        <apex:inputField value="{!memb.Name}"/>
                    </apex:column>
                    <apex:column headerValue="Opportunity Stage">
                        <apex:inputField value="{!memb.StageName}"/>
                    </apex:column>
                    <apex:column headerValue="Opportunity Amount">
                        <apex:inputField value="{!memb.Amount}"/>
                    </apex:column>
                    <apex:column headerValue="Opportunity Close Date">
                        <apex:inputField value="{!memb.CloseDate}"/>
                    </apex:column>
                </apex:pageBlockTable> 
                <br/><apex:commandLink value="+ Add Row" action="{!addRow}" reRender="membAdd"/>        
            </apex:pageblockSection>        
            <apex:pageblockSection columns="1" >
                <apex:pageblockSectionItem >
                    <apex:commandButton value="Save" /><apex:commandButton value="Cancel" />
                </apex:pageblockSectionItem>         
            </apex:pageblockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>
Appreciate your feedback to this answer, if it helps.
Thanks, Sunil.