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
jeevitha annabathula 5jeevitha annabathula 5 

how to autpopulate lookupfield when new child record is created using related list button. i want to do this with visual force page and after saving record it should go back to parent detailpage

<apex:page StandardController="Test_QuoteLine__c" extensions="Multiadd" id="thePage">
<apex:form >
<apex:pageblock id="pb" >
    <apex:pageBlockButtons >
        <apex:commandbutton value="Add Line Item" action="{!Add}" rerender="pb1"/>
        <apex:commandbutton value="Save QuoteLineItem" action="{!save}"/>
    </apex:pageBlockButtons>
    
        <apex:pageblock id="pb1">
            
        <apex:repeat value="{!lstInner}" var="e1" id="therepeat">
                <apex:panelGrid columns="6">
                
                <apex:panelGrid headerClass="Name">
                    <apex:facet name="header">Delete</apex:facet>
                    <apex:commandButton value="Remove" action="{!Del}" rerender="pb1">
                        <apex:param name="rowToBeDeleted" value="{!e1.recCount}" assignTo="{!selectedRowIndex}"></apex:param>
                    </apex:commandButton>
                </apex:panelGrid>   
                
                <apex:panelGrid title="SPD" >
                    <apex:facet name="header">Sales price</apex:facet>
                    <apex:inputfield value="{!e1.acct.Unit_Price__c}" required="false"/>
                </apex:panelGrid>
                
                <apex:panelGrid >
                    <apex:facet name="header">Quantity</apex:facet>
                    <apex:inputfield value="{!e1.acct.Quantity__c}" required="false"/>
                </apex:panelGrid>
                
                <apex:panelGrid >
                    <apex:facet name="header">Discount</apex:facet>
                    <apex:inputfield value="{!e1.acct.Discount__c}" required="false"/>
                </apex:panelGrid>
                    <apex:panelGrid >
                    <apex:facet name="header">Quote</apex:facet>
                    <apex:inputfield value="{!e1.acct.New_Quote__c}" required="false" />
                </apex:panelGrid>
                <apex:panelGrid >
                    <apex:facet name="header">Product</apex:facet>
                    <apex:inputfield value="{!e1.acct.Product__c}" required="false" />
                </apex:panelGrid>
      </apex:panelGrid>
        </apex:repeat>
    </apex:pageblock>
</apex:pageblock>
</apex:form>
</apex:page>



controller:
public class Multiadd
{
    
   
    public List<Test_QuoteLine__c>lstAcct  = new List<Test_QuoteLine__c>();
    private ApexPages.StandardController controller;
    public Multiadd(ApexPages.StandardSetController controller) {
        controller.setPageSize(10);
       
    }
    
      public List<innerClass> lstInner 
    {   get;set;    }
    
       public String selectedRowIndex
    {get;set;}  
    
     public Integer count = 1;
    //{get;set;}
    
     public PageReference Save()
    {
        PageReference pr = new PageReference('/a59/o');
        
        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);            
    
      public void Del()
    {
        system.debug('selected row index---->'+selectedRowIndex);
        lstInner.remove(Integer.valueOf(selectedRowIndex)-1);
        count = count - 1;
        
    }
    
    public MultiAdd(ApexPages.StandardController ctlr)
    {
    
        lstInner = new List<innerClass>();
        addMore();
        selectedRowIndex = '0';
        
    }
        
    public class innerClass
    {       
       
        public String recCount
        {get;set;}
        
        
        public Test_QuoteLine__c acct 
        {get;set;}
        
     
        public innerClass(Integer intCount)
        {
            recCount = String.valueOf(intCount);         
            /*create a new account*/
            acct = new Test_QuoteLine__c();
        acct.New_Quote__c = ApexPages.CurrentPage().getparameters().get('quoteId');
            
        }   
    }
}
quote value has to prepoulate here