I want auto populate contact and account fields when ever we create Opportunity record from contacts related list. But below was not giving as expected results...please anyone make correct.

PageReference pr = new PageReference('/apex/OppVfPage?CF00N40000002fEB2={!Contact.Name}&CF00N40000002fEB2_lkid={!Contact.Id}&conid={!Contact.Id}');

after page opens the contact or account fields were not populated and the URL displays like...


1 Answer 1


You are trying to create PageReference - and its constructor accepts String. But String is not a Formula, merge fields will not be populated. You must either format string properly or set parameters:

PageReference yourPage = Page.YourPage;
yourPage.getParameters().put('Id', contact.Id);
return yourPage;


PageReference yourPage = new PageReference('/apex/YporPage?Id=' + contact.Id); 
return yourPage;
  • I am forwarding conId in to Opportunity page....when ever i create a new opportunity from contact related list then i want to auto populate contact and account. but from above it doesn't work
    – arnian
    Aug 25, 2015 at 10:09
  • It is just example of how set paramethers in URL from code. There is some post about URL hack SF : salesforceben.com/salesforce-url-hacking-tutorial Aug 25, 2015 at 11:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .