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...



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 '15 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 '15 at 11:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.