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
VarunCVarunC 

Passing values as parameters in URL visualforce page

Hi I'm not able to pass a Field Value in URL to another page so that a Particular field is always prepopulated on page load.

I've my button code as this:
Code:
<apex:commandButton value="New Billing" onclick="javascript:{!URLFOR($Action.Billing__c.New,null,[retURL=URLFOR($Action.Task.View,task.Id),ActivityId__c=task.Id],false)}"/>
With this URL the value is Set correctly, but the value is not prefiled on page load :(.


 Now if I replace the value of URL to this:
Code:
<apex:commandButton value="New Billing" onclick="javascript:{!URLFOR($Action.Billing__c.New,null,[retURL=URLFOR($Action.Task.View,task.Id),00N80000002c4Qe=task.Id],false)}"/>

 Where 00N80000002c4Qe is ID value of the control on target page which is needed to be pre-populated. But this above throws me SYNTAX Error of missing Field Name.

Can anyone guide me how to properly Set Return URL as well as pass some custom values in URL from a VF page?


Best Answer chosen by Admin (Salesforce Developers) 
jlojlo

Here's some workaround code that you could modify if you don't want to hard code the field Ids:

 

Visualforce Page

<apex:page standardController="Contact" extensions="logMeetingExtension" action="{!createMeetingAndRedirect}"/>

 

Controller Extension

public class logMeetingExtension {
Contact contact;

public logMeetingExtension(ApexPages.StandardController controller) {
contact = (Contact)controller.getRecord();
}

public PageReference createMeetingAndRedirect() {
Event e = new Event(Subject = 'some subject');
e.DurationInMinutes = 60;
e.ActivityDateTime = System.now();
//fill in all the fields you like here
// ...

insert e;
return ApexPages.StandardController(e).edit();
}
}

 

This solution does have the drawback of creating a new record even if the user navigates away from the page before clicking on the "Save" button though...

All Answers

Ron HessRon Hess
Pre populating field values in standard (non visualforce) edit pages is not supported.
VarunCVarunC
So any idea on HOW can I populate a particular field value when i pass the value from a VF page to a standard controller page?
MPIMPI
http://community.salesforce.com/sforce/board/message?board.id=Visualforce&message.id=7322

You can get the field name by viewing the source of the edit page and seeing the id/name of the input.
MRutterMRutter

I have found the same problem with trying to pass values to custom fields inside the [] brackets.  The following works for me:

 

<script type="text/javascript">

window.parent.location.href="{!URLFOR($Action.Activity.NewEvent,null,
[retURL=URLFOR( $Action.Contact.View, Contact.Id)]
)} &00N80000002rqFh=Here&RecordType=01280000000EpvV&type=Event&setupid=EventRecords";

</script>

 

Mark

jlojlo

Here's some workaround code that you could modify if you don't want to hard code the field Ids:

 

Visualforce Page

<apex:page standardController="Contact" extensions="logMeetingExtension" action="{!createMeetingAndRedirect}"/>

 

Controller Extension

public class logMeetingExtension {
Contact contact;

public logMeetingExtension(ApexPages.StandardController controller) {
contact = (Contact)controller.getRecord();
}

public PageReference createMeetingAndRedirect() {
Event e = new Event(Subject = 'some subject');
e.DurationInMinutes = 60;
e.ActivityDateTime = System.now();
//fill in all the fields you like here
// ...

insert e;
return ApexPages.StandardController(e).edit();
}
}

 

This solution does have the drawback of creating a new record even if the user navigates away from the page before clicking on the "Save" button though...

This was selected as the best answer
Saurabh DhobleSaurabh Dhoble

You can look at the solution outlined in this series of posts.