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
Tre PedigoTre Pedigo 

Using a controller to modify the vf page URL

Hello all,

I have two objects (Taskray Project and Taskray Task). Within each taskray task I would like to display specific detail fields about its related taskray project. I have created a visual force page for this, but my problem is that (from what I can tell) the visual force page does not recognize the relationship between the two objects unless the record id is entered into the URL. So my question is, is it possible to edit the URL of the vf page to include this record id through the usage of a controller. And if so, how would I go about doing that? My thought process is that the controller would grab the related taskray project depending on what taskray task was currently opened, grab the record id of the project and then place it into the URL of the vf page so that the vf page knows which record it needs to pull data from. 

Also, i'm pretty new to salesforce so any sample code on how to do this would be greatly appreciated!
Thank you all

Tre PedigoTre Pedigo
I am willing to clear up any confusion there is with my question as well.
Newbie__SalesforceNewbie__Salesforce
Hello Tre,

According to my understanding I have drafted a scenario

Example - I have a list of Contact record displayed in VF page, when I click on a contact record its parent Account should be displayed
For the above functionality you can use pagereference and append account id for the same
Tre PedigoTre Pedigo
Hey there,

Thanks for the response, but that's not quite what I'm looking for. Here is what I need to see.

Example - If I have an extra tab within a contacts' page (this would be the vf page) then I need it to display additional details about that specific contact automatically.
Newbie__SalesforceNewbie__Salesforce
So you only need to change url with a new id and stay on the same page. For the same you can use pagereference and set redirect to false so that viewstate is preserved and you are able to add url

For reference - 
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_System_PageReference_setRedirect.htm