You need to sign in to do that
Don't have an account?
Anto Hotelbeds
Passing parameter in URL to a visualforce page
Hi,
I have a custom button, Close Lead, that redirects the user to a visualforce page.
This is the URL of the visualforce page:
https://c.cs8.visual.force.com/apex/CloseLeadReason?Status=Lead%20Closed&id=00QL0000001wv7v
And this is the visualforce page. very simple, just showing to fields, lead status and lead status result:
<apex:page standardController="Lead" showHeader="true"> <apex:sectionHeader title="Lead Edit" subtitle="{!Lead.Company}"/> <apex:form > <apex:pageBlock title="Lead Edit" id="Edit_Fiscal_Information" mode="Edit"> <apex:pageMessages /> <apex:pageBlockButtons > <apex:commandButton value="Close" action="{!save}"/> <apex:commandButton value="Cancel" action="{!cancel}"/> </apex:PageBlockButtons> <apex:pageBlockSection columns="2"> <apex:pageBlockSectionItem > <apex:outputLabel value="Lead Status"/> <apex:inputField value="{!lead.Status}"/> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="Lead Status Result"/> <apex:inputField value="{!lead.Lead_Status_Result__c}"/> </apex:pageBlockSectionItem> </apex:pageblockSection> </apex:pageBlock> </apex:form> </apex:page>
I want to prepopulate the field status with the value of the picklist 'Lead Closed' using the URL, but I am not able to do so.
Can anyone show me how to get it?
Thanks a lot!
Antonio
Hi,
You can do this by extension and load the status field value but the problem is when you use it by extension then the standard save button will not work for this field as it will display as different object variable. For that case you have to use custom save method to achieve this functionality.
The Extension will be like this
public with sharing class LeadController{
public Lead ldObj{get;set;}
public LeadController(ApexPages.StandardController controller){
//Fetching the Current Lead Record
this.ldObj = (Lead)controller.getRecord();
}
ldObj.Status = System.currentPageReference().getParameters().get('Status');
}
Page
<apex:page standardController="Lead" showHeader="true" extensions="LeadController">
<apex:sectionHeader title="Lead Edit" subtitle="{!Lead.Company}"/>
<apex:form >
<apex:pageBlock title="Lead Edit" id="Edit_Fiscal_Information" mode="Edit">
<apex:pageMessages />
<apex:pageBlockButtons >
<apex:commandButton value="Close" action="{!save}"/>
<apex:commandButton value="Cancel" action="{!cancel}"/>
</apex:PageBlockButtons>
<apex:pageBlockSection columns="2">
<apex:pageBlockSectionItem >
<apex:outputLabel value="Lead Status"/>
<apex:inputField value="{!ldObj.Status}"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Lead Status Result"/>
<apex:inputField value="{!lead.Lead_Status_Result__c}"/>
</apex:pageBlockSectionItem>
</apex:pageblockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.
Thanks
All Answers
Thanks for your reply but I already tried what many web pages indicate and I didnt get it. I even tried to populate a different field just in case as follows:
https://c.cs8.visual.force.com/apex/CloseLeadReason?scontrolCaching=1&id=00QL0000001wv7v&00ND0000004ToZg=Street
I am wondering wether this is possible only when creating a new record or when modifying an existing one too? What I try to do here is to modify an existing lead.
Thanks,
Antonio
I guess you have to use extension to set the value to desired value
Hi,
You can do this by extension and load the status field value but the problem is when you use it by extension then the standard save button will not work for this field as it will display as different object variable. For that case you have to use custom save method to achieve this functionality.
The Extension will be like this
public with sharing class LeadController{
public Lead ldObj{get;set;}
public LeadController(ApexPages.StandardController controller){
//Fetching the Current Lead Record
this.ldObj = (Lead)controller.getRecord();
}
ldObj.Status = System.currentPageReference().getParameters().get('Status');
}
Page
<apex:page standardController="Lead" showHeader="true" extensions="LeadController">
<apex:sectionHeader title="Lead Edit" subtitle="{!Lead.Company}"/>
<apex:form >
<apex:pageBlock title="Lead Edit" id="Edit_Fiscal_Information" mode="Edit">
<apex:pageMessages />
<apex:pageBlockButtons >
<apex:commandButton value="Close" action="{!save}"/>
<apex:commandButton value="Cancel" action="{!cancel}"/>
</apex:PageBlockButtons>
<apex:pageBlockSection columns="2">
<apex:pageBlockSectionItem >
<apex:outputLabel value="Lead Status"/>
<apex:inputField value="{!ldObj.Status}"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Lead Status Result"/>
<apex:inputField value="{!lead.Lead_Status_Result__c}"/>
</apex:pageBlockSectionItem>
</apex:pageblockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.
Thanks
I am having an issue implementing this. I am trying to pass a variable from the URL, into the VF page, then into a flow.
I have written a custom controller already that sets the finish location of the flow but I need to be able to pass an ID into the flow from the URL.
The application is to create run the InboundTechCall (ie: create a new case) flow from a Contact record.
I am currently getting the controller error: Error: Compile Error: Invalid constructor name: ContactController at line 8 column 12
Controller
public with sharing class CreateCase {
public String getInboundTechCall() {
return null;
}
public Contact cnObj{get; set;}
public ContactController(ApexPages.StandardController controller){
//Fetching the Current Contact Record
this.cnObj = (Contact)controller.getRecord();
}
Public String ContactID {get; set;}
ContactID = cnObj.Id;
public String getCaseId(){ return getcaseID; }
public ID getcaseID = System.currentPagereference().getParameters().get('cid');
public Flow.Interview.Inbound_Tech_Call caseID{get;set;}
public ID returnId = getcaseId;
public PageReference getFinishURL(){
if(caseID != null) returnId = caseID.caseID;
PageReference send = new PageReference('/' + returnId);
send.setRedirect(true);
return send;
}
}
VF Page:
<apex:page Controller="CreateCase" standardStylesheets="false" sidebar="true" showHeader="true" tabStyle="Case">
<!-- Run Flow -->
<flow:interview buttonStyle="color:black; background-color:#FEFCFF; border:2px;" name="Inbound_Tech_Call" showHelp="true" interview="{!caseID}" finishLocation="{!finishURL}" buttonLocation="both">
<apex:param name="caseID" value="{!caseID}"/>
<apex:param name="ContactID" value="{!ContactID}"/>
</flow:interview>
</apex:page>
Your constructor name should always match the classname. The apex controller name is "CreateCase" where as the constructor name is "
ContactController which is wrong. Also since you are not using StandardController the constructor in the class is not required. All you can do is to change the vf page dclaration as follows.
<apex:page StandardController="Case" extensions="CreateCase" standardStylesheets="false" sidebar="true" showHeader="true" tabStyle="Case">