[SalesForce] How to override a new related list button to redirect to a VF page (custom controller)

My new related list button should redirect me to the New VF page for the child object, with certain fields from the Master on this form pre-filled. I can't seem to be able to both prefill the fields belonging to the Master or associate the new Child with the same Master. The VF page has a custom controller.

I tried using the format /apex/pageName?retURL=sameAsStdNewButton&lookupField_lkid={!Master__c.id}&MasterFieldToBePrefilledId1={!Master__c.Field__c}&... but it doesn't seem to work.

It would also be helpful if someone could tell me how to structure the saveURL.

Best Answer

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