If you are using a custom visualforce page in redirect URL then simply leverage parameters as given below:
New Button URL:
/apex/myVisualforcePage?masterId={!master__c.Id}&retURL=/{!master__c.Id}
Actual link will be:
https://c.eu0.visual.force.com/apex/myVisualforcePage?masterId=a08200000148XpNAAU&retURL=%2F%2Fa08200000148XpN&nooverride=1
Now you can leverage parameter name "masterId" to fill in the Visualforce page input field.
If you are trying to redirect to a page which don;t have controller you can do it like:
New Button URL:
https://c.eu0.visual.force.com/apex/myVisualforcePage?{!IdOfMasterCustomField}={!Master__c.Name}&{!IdOfMasterCustomField}_lkid={!Master__c.id}
Actual link will be shown as:
https://c.eu0.visual.force.com/apex/myVisualforcePage?CF00N20000007hitQ=ER-000722&CF00N20000007hitQ_lkid=a0B2000000h3sgc
One common misconception is that getRecord()
works like trigger contexts and the entire Opportunity record is available to the controller. Not true. getRecord()
only makes available to the controller the fields defined on the page of the form e.g. {!Opportunity.xxx}
- these can be hidden fields -- or, you can use method addFields()
.
here is the standard controller doc but I've excerpted the relevant bits:
getRecord()
Usage
Note that only the fields that are referenced in the associated Visualforce markup are available for querying on this SObject. All
other fields, including fields from any related objects, must be
queried using a SOQL expression.
Tip
You can work around this restriction by including a hidden component that references any additional fields that you want to
query. Hide the component from display by setting the component's
rendered attribute to false.
addFields(...)
When a Visualforce page is loaded, the fields accessible to the page are based on the fields referenced in the Visualforce markup. This method adds a reference to each field specified in fieldNames so that the controller can explicitly access those fields as well.
Usage
This method should be called before a record has been loaded—typically, it's called by the controller's constructor. If this
method is called outside of the constructor, you must use the reset()
method before calling addFields().
The strings in fieldNames can either be the API name of a field, such as AccountId, or they can be explicit relationships to fields,
such as foo__r.myField__c.
So it is up to you which way to go, for example with addFields you could do in your constructor...
myController.addFields(new List<String> {'ownerId','amount'});
opp=(Opportunity)myController.getrecord();
Best Answer
Step 1: Open respective Account page layout
Step 2: Open Opportunity Related list properties
Step 3: Open Button section
Step 4: uncheck New checkbox