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
RDN_LHRRDN_LHR 

Putting in defaults in Visualforce Page

 
Hi,

 

I would like to mimic a bit of Salesforce behavior in a Visualforce Page I'm creating.

 

Examples: When you're on a Contact page and you click New Task, the contact's detail is filled in for you.  When you're on an Opportunity page and you click New Task, the opportunity's detail gets placed in the Related To box for you.  There are countless examples of this behavior all over Salesforce

 

I have a custom object called Trial.  It has lookup fields called Campaign, Contact and Opportunity which I'm putting on my custom Visualforce Page which represents a wizard's "Step 1." 

 

I'll add a custom button on Campaign, Contact and Opportunity called "New Trial" which will call this page and pass parameters to it off the record it's being called from.

 

On the page, I've got the three fields as  <apex:inputField>.   How do I get values in those fields the same way Salesforce does?

Best Answer chosen by Admin (Salesforce Developers) 
Sam.arjSam.arj

It seems that Visualforce does not match the parameters passed via url to the new object.

 

So you need to set the values from URL parameters yourself in yoru VF page's constructor.

 

If URL parameters such as Campaign Id is not passed, then you should revise your custom button to make sure the IDs are passed through via URL.