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
MLamb2005MLamb2005 

Visualforce page to do SQL query and redirect

Hi all,

 

I have three objects, Lab Projects (Master), Employee (Master), and Lab Project Hour (Junction between Lab Projects and Employee).  Lab Project Hours records are always created from a Lab Projects record, so the Edit page always has the Master-Detail field Lab Project Name auto-filled.

 

What I'm looking to do is auto-fill the Master-Detail field Employee Name.  The necessary data is on the current user's User record in the Employee ID field, and I've written the following SQL statement to access it:

 

 

Id employeePageId = [Select Employee_Page__c from User where Id = : UserInfo.getUserId() Limit 1].Employee_Page__c;

 

So what I'm looking to do is build a Visualforce page that overwrite the 'New' button on the related list Lab Project Hours that will:

 

  • Execute the above SQL query to get the necessary record ID
  • Re-direct users to the standard Edit page for Lab Project Hours
  • Populate the Employee record ID (that was found from the SQL query) into the Employee Name field


If anyone can point me to some resources I'd be greatful, this is my first foray into VF.


Thansk!
Matt