1

I'm stuck and want a way to solve a problem . The requirement is when i click on custom button it should redirect me to the Contact page WITH auto populate Account field. I've reach with the redirect and stucked with auto populate . How do i do it ? Thanks in advance. Any modifications with my code would be helpful.

<apex:page standardController="Contact" extensions="NewContact">
  <apex:form >
<apex:pageBlock title="New Contact " mode="edit">
 <apex:pageBlockButtons >
    <apex:commandButton action="{!Cancel}" value="Cancel"/>
  </apex:pageBlockButtons>

<apex:pageBlockSection title="Contact Details" columns="2">
  <apex:CommandButton action="{!NewImplementation}" value="New Implementation" />
</apex:pageblocksection>

  == Class==


  public class NewContact {

   public NewContact(ApexPages.StandardController controller) {
   }
   public PageReference NewImplementation() {
     PageReference secondPage = new PageReference ('/003/e');
     secondPage.setRedirect(true);        
     return secondPage; 
    }
}
4
  • Where do you want this button to appear? Aug 25, 2014 at 14:09
  • I've already created a button and clicking on it , it is redirecting me to Contact page . Now the issue is , Account Name field should be auto populated when i click on the same button.
    – JJoseph
    Aug 25, 2014 at 14:12
  • You are not answering my question. Where do you want this button to appear? On Account detail page? Aug 25, 2014 at 14:13
  • Button is simply displayed on a custom Vf page. I do not want the button to appear. For button i've made custom vf page.
    – JJoseph
    Aug 25, 2014 at 14:15

1 Answer 1

1

To pre-populate a field you can use some url parameters. The process is described in this blog article:

http://simplysfdc.blogspot.de/2012/11/custom-button-to-prepulate-field.html

There is also a youtube video which explains the process:

https://www.youtube.com/watch?v=_WHpTOF3bFo

Suggestion

In your case you have to add 2 parameters to the PageReference url. like

PageReference secondPage = new PageReference ('/003/e?MYFIELDID_lkid=ACCOUNT_RECORD_ID&MYFIELD_ID=ACCOUNT_Name');

Replace MYFIELDIDwith the account field ID. The ACCOUNT_RECORD_ID with your account ID and ACCOUNT_NAME with the account name.

2
  • It will be helpful if you can help me with any additions with my code. Pressing my head.
    – JJoseph
    Aug 25, 2014 at 14:13
  • @JJoseph - The answer given already does what you ask...We do not write code for you rather we provide you with the means to understand how to do it and update your own code. If you do not understand the answer please clarify where you are having difficulty
    – Eric
    Aug 25, 2014 at 15:18

You must log in to answer this question.

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