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
Swetha Sfdc1Swetha Sfdc1 

How to Seperate Lookup Field from Add/Remove Functionality

Hi Friends,
Thanks in advance, I am facing problem with Looup field ,I want it should seperate from section, please help me over here .

Note:
1--> I dont want to enter looup field multiple of times insted of that I want it should be header.
2--> Lookup field value is manditory for entire page.

I found issue is in Controller ( public multiadd(ApexPages.StandardController ctlr))

VF page code
<apex:page StandardController="mycontroller__c" extensions="multiadd" id="thePage" sidebar="false">

<apex:form >
<apex:pageblock id="pb" >
    <apex:pageBlockButtons >
        <apex:commandbutton value="Add" action="{!Add}" rerender="pb1"/>
        <apex:commandbutton value="Save" action="{!Save}"/>
    </apex:pageBlockButtons>
        
         <table width="100%">                
                <tr width="100%"><th><center>HelpPortal</center></th></tr>                     
                     <tr>
                        <td rowspan="4"></td>
                      </tr>
                      <tr>
                        <td><h1 style="text-align:center;color:blue;">Text1 &nbsp;:&nbsp;&nbsp;<apex:inputText value="{!Tour_Plan__c.Text1__c}" style="width:50px;height:20px;"/></h1></td>
                        <td><h1 style="text-align:center;color:blue;">Text2 &nbsp;:&nbsp;&nbsp;<apex:inputText value="{!Tour_Plan__c.Text2__c}" style="width:50px;height:20px;"/></h1></td>
                      </tr>
                      <tr>
                        <td><h1 style="text-align:center;color:blue;">Text3 &nbsp;:&nbsp;&nbsp;<apex:inputText value="{!Tour_Plan__c.Text3__c}" style="width:130px;height:20px;"/></h1></td>
                        <td><h1 style="text-align:center;color:blue;">Text4 &nbsp;:&nbsp;&nbsp;<apex:inputText value="{!Tour_Plan__c.Text4__c}" style="width:50px;height:20px;"/></h1></td>                        
                      </tr>
                      <tr>
                        <td><h1 style="text-align:center;color:blue;">Text5 &nbsp;&nbsp;&nbsp;
                        <apex:inputText value="{!Tour_Plan__c.DATE_OF_TRAVEL__c}" style="width:50px;height:20px;"/></h1></td>
                        <td></td>                      
                        </tr>
                </table>
        <apex:pageblock id="pb1">              
        <apex:repeat value="{!lstInner}" var="e1" id="therepeat">
                <apex:panelGrid columns="16"> 
                
                <apex:panelGrid title="Date" >
                    <apex:facet name="header">Date</apex:facet>
                    <apex:inputfield value="{!e1.acct.Date__c}"  style="width:50px;height:20px;"/>
                </apex:panelGrid>  
                                                
                <apex:panelGrid title="Unit Cost" >
                    <apex:facet name="header">Text1</apex:facet>
                    <apex:inputfield value="{!e1.acct.Text1__c}"  style="width:50px;height:20px;"/>
                </apex:panelGrid>
                
                <apex:panelGrid title="Nights" >
                    <apex:facet name="header">Text2</apex:facet>
                    <apex:inputfield value="{!e1.acct.Text2__c}"  style="width:50px;height:20px;"/>
                </apex:panelGrid>
                
                <apex:panelGrid title="Twin" >
                    <apex:facet name="header">Text3</apex:facet>
                    <apex:inputfield value="{!e1.acct.Text3__c}"  style="width:50px;height:20px;"/>
                </apex:panelGrid>
                
                <apex:panelGrid title="Tripl" >
                    <apex:facet name="header">Text4</apex:facet>
                    <apex:inputfield value="{!e1.acct.Text4__c}"  style="width:50px;height:20px;"/>
                </apex:panelGrid>
                
                
                <apex:panelGrid >
                    <apex:facet name="header">Text5</apex:facet>
                    <apex:inputfield value="{!e1.acct.Text5__c}"  style="width:50px;height:20px;"/>
                </apex:panelGrid>
                
                
                
                <apex:panelGrid >
                    <apex:facet name="header">Text6</apex:facet>
                    <apex:inputfield value="{!e1.acct.Text6__c}"  style="width:50px;height:20px;"/>
                </apex:panelGrid>
                
                                
                <apex:panelGrid >
                    <apex:facet name="header">Text7</apex:facet>
                    <apex:inputfield value="{!e1.acct.Text7__c}"  style="width:50px;height:20px;"/>
                </apex:panelGrid>
                
                <apex:panelGrid >
                    <apex:facet name="header">Dependency Lookup</apex:facet>
                    <apex:inputfield value="{!e1.acct.CustomName__c}"  style="width:50px;height:20px;"/>
                </apex:panelGrid>
                
                <apex:panelGrid headerClass="Name">
                    <apex:facet name="header">Del</apex:facet>
                    <apex:commandButton value="X" action="{!Del}" rerender="pb1">
                        <apex:param name="rowToBeDeleted" value="{!e1.recCount}" assignTo="{!selectedRowIndex}"></apex:param>
                    </apex:commandButton>
                </apex:panelGrid>                 
            </apex:panelgrid>
        </apex:repeat>
    </apex:pageBlock> 
</apex:pageblock>
</apex:form>
</apex:page>
Controller
public class multiadd
{
    
    //will hold the mycontroller__c records to be saved
    public List<mycontroller__c>lstAcct  = new List<mycontroller__c>();
    
    //list of the inner class
    public List<innerClass> lstInner 
    {   get;set;    }
    
    //will indicate the row to be deleted
    public String selectedRowIndex
    {get;set;}  
    
    //no. of rows added/records in the inner class list
    public Integer count = 1;
    //{get;set;}
    
    
    ////save the records by adding the elements in the inner class list to lstAcct,return to the same page
    public PageReference Save()
    {
        PageReference pr = new PageReference('/apex/multiaddSuccessPage');
        
        for(Integer j = 0;j<lstInner.size();j++)
        {
            lstAcct.add(lstInner[j].acct);
        } 
        insert lstAcct;
        pr.setRedirect(True);
        return pr;
    }
        
    //add one more row
    public void Add()
    {   
        count = count+1;
        addMore();      
    }
    
    /*Begin addMore*/
    public void addMore()
    {
        //call to the iner class constructor
        innerClass objInnerClass = new innerClass(count);
        
        //add the record to the inner class list
        lstInner.add(objInnerClass);    
        system.debug('lstInner---->'+lstInner);            
    }/* end addMore*/
    
    /* begin delete */
    public void Del()
    {
        system.debug('selected row index---->'+selectedRowIndex);
        lstInner.remove(Integer.valueOf(selectedRowIndex)-1);
        count = count - 1;
        
    }/*End del*/
    
    
    
    /*Constructor*/
    public multiadd(ApexPages.StandardController ctlr)
    {
    
        lstInner = new List<innerClass>();
        addMore();
        selectedRowIndex = '0';
        
    }/*End Constructor*/
        


    /*Inner Class*/
    public class innerClass
    {       
        /*recCount acts as a index for a row. This will be helpful to identify the row to be deleted */
        public String recCount
        {get;set;}
        
        
        public mycontroller__c acct 
        {get;set;}
        
        /*Inner Class Constructor*/
        public innerClass(Integer intCount)
        {
            recCount = String.valueOf(intCount);        
            
            /*create a new mycontroller__c*/
            acct = new mycontroller__c();
            
        }/*End Inner class Constructor*/    
    }/*End inner Class*/
}/*End Class*/

Requirement

Note:
1--> I dont want to enter looup field multiple of times insted of that I want it should be header.
2--> Lookup field value is manditory for entire page.

showing Error if Lookup field removed

Error


 
Rahul_SalesforceRahul_Salesforce
After "Text 5" field in the header section create add a lookup field by using inputField tag.

<inputField value="{!objInClass.acct.CustomName__c}"></inputField>

In the controller add the below lines of code::

public innerClass objInClass {get; set;}

Now in the save method 
public PageReference Save()
    {

        PageReference pr = new PageReference('/apex/multiaddSuccessPage');
        //below line of code added
       string CustomerId= objInClass.acct.CustomName__c;
        for(Integer j = 0;j<lstInner.size();j++)
        {
            //below line of code added
            lstInner[j].acct.CustomName__c=CustomerId;
            lstAcct.add(lstInner[j].acct);
        }
        insert lstAcct;
        pr.setRedirect(True);
        return pr;
    }

    I have not compiled the code , but you should try something like above and it will work.
Let me know if you face any issues
 
Swetha Sfdc1Swetha Sfdc1
Hi Rahul,

I tried this code But nothing happened, After saving Controller, input field is not showing in VF page <apex:inputField value="{!objInClass.acct.CustomName__c}"/>.

Please anybody help regarding this Issue.

Thanks & regards
Swetha
Rahul_SalesforceRahul_Salesforce
objInClass = new  innerClass ();
add above line of code after 
public innerClass objInClass {get; set;}


 
Swetha Sfdc1Swetha Sfdc1
Hi Rahul, Thanks for your response, I am getting compile time Error,
Compiletime error

I have tried other ways also
->InnerClass objInClass = new InnerClass(); //Compile Error: Duplicate variable: objInClass (attempt to re-create the variable with type: InnerClass) at line 5 column 15
->OuterClass.InnerClass innerObject = outerObject.new InnerClass(); //(Nested Class)
But I am unable to move further.

Thanks & regards
Swetha