You need to sign in to do that
Don't have an account?
Shawn Reichner 29
Populating lookup field on visualforce page from extension
Hello awesome developers!
I am stuck here, and I will be up front I am prety new to the apex extension for VF pages.
I am attempting to as a record is closed, send an email from a workflow with an url to a VF page for an user to fill out a brief survey. I am attempting to place a parameter in the URL of the closing records ID to then pre populate the lookup field on the VF page with the ID of the closing record that is sending the survey needed email.
I have the following VF page built and extension, however when the page is loaded, the lookup field on the VF page is not being populated. Any ideas on what I did incorrectly and or ideas on how to make this work?
I appreciate any input,
PS...once this is working, since I am new to the extension building, any insights on building a test class for the extension?
Shawn
VF Page:
Extension:
I am stuck here, and I will be up front I am prety new to the apex extension for VF pages.
I am attempting to as a record is closed, send an email from a workflow with an url to a VF page for an user to fill out a brief survey. I am attempting to place a parameter in the URL of the closing records ID to then pre populate the lookup field on the VF page with the ID of the closing record that is sending the survey needed email.
I have the following VF page built and extension, however when the page is loaded, the lookup field on the VF page is not being populated. Any ideas on what I did incorrectly and or ideas on how to make this work?
I appreciate any input,
PS...once this is working, since I am new to the extension building, any insights on building a test class for the extension?
Shawn
VF Page:
<apex:page standardController="Salesforce_Support_Survey__c" sidebar="false" showHeader="false" extensions="SalesforceSupportSurveyController" docType="html-5.0"> <style> html, body, p { font-family: "ProximaNovaSoft-Regular", Calibri, "Gill Sans", "Gill Sans MT", Candara, Segoe, "Segoe UI", Arial, sans-serif; font-size: 110%; } input { font-size: 95%; } </style> <apex:form > <apex:pageBlock title="Thank you for taking our short survey!" mode="edit"> <apex:pageBlockButtons > <apex:commandButton action="{!save}" value="Submit Survey"/> </apex:pageBlockButtons> <apex:pageBlockSection title="Survey Questions:" columns="2"> <apex:outputField value="{!Salesforce_Support_Survey__c.X1_Timliness__c}"/> <apex:inputField value="{!Salesforce_Support_Survey__c.X1_Answer__c}"/> <apex:outputField value="{!Salesforce_Support_Survey__c.X2_Satisfaction__c}"/> <apex:inputField value="{!Salesforce_Support_Survey__c.X2_Answer__c}"/> <apex:outputField value="{!Salesforce_Support_Survey__c.X3_Submission_process__c}"/> <apex:inputField value="{!Salesforce_Support_Survey__c.X3_Answer__c}"/> <apex:outputField value="{!Salesforce_Support_Survey__c.X4_Enhancement_Ideas__c}"/> <apex:inputField value="{!Salesforce_Support_Survey__c.X4_Answer__c}"/> <apex:outputField value="{!Salesforce_Support_Survey__c.X5_Additional_Comments__c}"/> <apex:inputField value="{!Salesforce_Support_Survey__c.X5_Answer__c}"/> <apex:inputField value="{!Salesforce_Support_Survey__c.Issue__c}"/> <script> document.getElementById('{!$Component.dynFieldName}_lkid').value = '{!IssueId}'; document.getElementById('{!$Component.dynFieldName}').value = '{!IssueName}'; </script> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
Extension:
public class SalesforceSupportSurveyController { public string IssueId { get;set; } public string IssueName { get;set; } public SalesforceSupportSurveyController(ApexPages.StandardController ctlr) { IssueId = System.currentPageReference().getParameters().get('lookupVal'); IssueName = [select Name from SFDC_Issue__c where Id =: IssueId].Name; } }
All Answers
1. If you have to get something from the URL , you should have the query string passed into it . I dont see you have set up the query string
2. Double check if your form is submitted in GET||POST method . If it is POST method you will not get anything from URL
3. As best practice dont expose the ids to the users instead do some basic encryption so that there will be no accident exposure of sensitive information