0

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

https://c.cs15.visual.force.com/apex/OppVfPage?CF00N40000002fEB2=%7B%21Contact.Name%7D%3FCF00N40000002fEB2_lkid%3D%7B%21Contact.Id%7D%3Fconid%3D%7B%21Contact.Id%7D

1 Answer 1

2

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; 

OR

PageReference yourPage = new PageReference('/apex/YporPage?Id=' + contact.Id); return yourPage; 
2
  • 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 Commented 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 Commented Aug 25, 2015 at 11:29

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.