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
Andrew Hoban 6Andrew Hoban 6 

How to default a lookup field when a new row has been clicked.

Hi all,

I am trying to populate a lookup field (Match_Day_Ops__c) every time the 'add new' button is clicked. I have created a visualforce page that allows a new row of fields to be added on the pae without refreshing. 

Visualforce Page:
<apex:page sidebar="false" StandardController="Incident_Log__c"  extensions="IncidentLogPopup">
<apex:form >
    <apex:pageBlock id="membAdd" >  
    <apex:pageBlockButtons location="Both">
                <apex:commandButton value="Save" Action="{!save}" />
                <apex:commandButton value="Cancel" action="{!cancel}"/>
        <apex:pageblockSection >       
            <apex:pageBlockTable value="{!memberAddList}" var="memb">
                <apex:column headerValue="Match Day Ops">
                    <apex:inputField value="{!memb.Match_Day_Ops__c}"/>
                 <apex:column headerValue="Priority">
                    <apex:inputField value="{!memb.Priority__c}"/>
                  <apex:column headerValue="Date/Time">
                    <apex:inputField value="{!memb.Date_Time__c}"/>
                <apex:column headerValue="Incident Open">
                    <apex:inputField value="{!memb.Incident__c}"/>
                <apex:column headerValue="Date/Time Closed">
                    <apex:inputField value="{!memb.Date_Closed__c}"/>
                <apex:column headerValue="Incident Closed">
                    <apex:inputField value="{!memb.Incident_Closed__c}"/>
                <apex:column headerValue="Reported To">
                    <apex:inputField value="{!memb.Reported_To__c}"/>
                <apex:column headerValue="Reported By">
                    <apex:inputField value="{!memb.Reported_By__c}"/>
            <br/><apex:commandLink value="Add Row" action="{!addRow}" reRender="membAdd" />        
        <apex:pageblockSection columns="1" >
            <apex:pageblockSectionItem >

public class IncidentLogPopup
    public IncidentLogPopup(ApexPages.StandardSetController controller) {


    public List<Incident_Log__c> memberList {get;set;}
    public List<Incident_Log__c> memberAddList {get;set;}
    public String memberName {get;set;} 
    public string searchstring {get;set;}  
    public IncidentLogPopup(ApexPages.StandardController controller) {
        String sql = 'SELECT Match_Day_Ops__c, Date_Time__c, Date_Closed__c, Priority__c, Incident__c, Reported_to__c, Reported_By__c, Opened_Closed_Status__c FROM Incident_Log__c';
        memberList = Database.Query(sql);
        memberAddList = new List<Incident_Log__c>();
        memberAddList.add(new Incident_Log__c());

    public void AddRow()
        memberAddList.add(new Incident_Log__c());
    Public Pagereference Save(){
        insert memberAddlist;
        return null;


Best Answer chosen by Andrew Hoban 6
In Your Controller on line 26, you can set default value which would be available in Visualforce page.
memberAddList.add(new Incident_Log__c(myField__c = 'I am default value'));