You need to sign in to do that
Don't have an account?
Andrew 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:
Controller:
Thanks
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:pageBlockButtons> <apex:pageblockSection > <apex:pageBlockTable value="{!memberAddList}" var="memb"> <apex:column headerValue="Match Day Ops"> <apex:inputField value="{!memb.Match_Day_Ops__c}"/> </apex:column> <apex:column headerValue="Priority"> <apex:inputField value="{!memb.Priority__c}"/> </apex:column> <apex:column headerValue="Date/Time"> <apex:inputField value="{!memb.Date_Time__c}"/> </apex:column> <apex:column headerValue="Incident Open"> <apex:inputField value="{!memb.Incident__c}"/> </apex:column> <apex:column headerValue="Date/Time Closed"> <apex:inputField value="{!memb.Date_Closed__c}"/> </apex:column> <apex:column headerValue="Incident Closed"> <apex:inputField value="{!memb.Incident_Closed__c}"/> </apex:column> <apex:column headerValue="Reported To"> <apex:inputField value="{!memb.Reported_To__c}"/> </apex:column> <apex:column headerValue="Reported By"> <apex:inputField value="{!memb.Reported_By__c}"/> </apex:column> </apex:pageBlockTable> <br/><apex:commandLink value="Add Row" action="{!addRow}" reRender="membAdd" /> </apex:pageblockSection> <apex:pageblockSection columns="1" > <apex:pageblockSectionItem > </apex:pageblockSectionItem> </apex:pageblockSection> </apex:pageBlock> </apex:form> </apex:page>
Controller:
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; } }
Thanks
Best Answer chosen by Andrew Hoban 6
Jitendra
In Your Controller on line 26, you can set default value which would be available in Visualforce page.