There is master_account__c lookup(Account), Account(standard field) on Opportunity i am trying to prepopulate both the values with same Account field through custom button.I am able to prepouplate Account field but failed to update master_account__c lookup(Account).

Custom button code: /006/e?&accid={!Account.Id}

VF page for record type selection:

<apex:page standardController="Opportunity" tabStyle="Opportunity"  extensions="OpportunityRecordTypeSelection">
   <apex:sectionHeader title="New Opportunity" subtitle="Select Opportunity Record Type"/>
        <apex:form id="theForm">
            <apex:pageBlock title="Select Opportunity Record Type">
                <apex:pageBlocksection >
                    <apex:pageBlockSectionItem >
                        <apex:outputLabel > RecordType of new record </apex:outputLabel>
                        <apex:selectList size="1"  value="{!selectedRecordType}"  >
                            <apex:selectOptions value="{!RecordTypeList}" />

                <apex:pageBlockButtons location="bottom">       
                    <apex:pageBlocksection >
                        <apex:pageBlockSectionItem > 
                            <apex:commandButton action="{!continueToOpportunity}" value="Continue" />
                            <apex:commandButton onclick="CloseTab();return false;" action="{!cancelRec}" value="Cancel"/>

Apex controller:

public class OpportunityRecordTypeSelection
        Opportunity a;
        ApexPages.StandardController controller;
         public Id accid;

        public OpportunityRecordTypeSelection(ApexPages.StandardController controller)
            this.controller = controller;
            a = (Opportunity) Controller.getRecord();
         accid = ApexPages.currentPage().getParameters().get('accid');

public PageReference continueToOpportunity() 

            if((selectedRecordType =='PM-P Opportunity' || selectedRecordType =='FPD PR Opportunity' || selectedRecordType =='IR3535 EU' ||selectedRecordType )

           Id devRecordTypeId = Schema.getGlobalDescribe().get('Opportunity').getDescribe().getRecordTypeInfosByName().get(selectedRecordType).getRecordTypeId(); 

                PageReference pageRef=new PageReference('/006/e?retURL=%2F006%2Fo&accid='+accid+'&RecordType='+devRecordTypeId+'&ent=Opportunity&Master_Account__c='+accid+'&RecordType='+devRecordTypeId+'&ent=Opportunity');
                return pageRef;

Please find the URL i am getting once i clicked on continue. enter image description here

enter image description here

1 Answer 1


This blog goes into detail on how to use urlhacking to prepopulate a custom lookup field.

To populate a Lookup value we need the field ID as before but this time we need to add CF to the front of the ID so it looks something like this – CF00Ni000000EpsgO. This is required when populating a custom lookup field. The first part to populate a lookup value is to grab the name of the record we are populating. So using the method before but with the added CF you can expect your button URL to look like this


The next step is to grab the ID of the record we wish to populate. This time though, we are going to add “_lkid” to the end of our field ID (plus the CF we added on earlier). This lkid parameter is telling Salesforce this is a lookup field. So it looks a bit like this.


  • Thank you for your time @Todd Sprinkel. "/a0U/e?CF00Ni000000EpsgO={!Opportunity.Name}&CF00Ni000000EpsgO_lkid={!Opportunity.Id} " This will work after New button. There will be Recordselection VF page after New button. In which i need to click on Continue button for the creation of Opportunity. I have given The controller and VF page code. How should i pass this lookup field in Pagerefernce method?
    – User 7864
    Aug 3, 2017 at 15:09

You must log in to answer this question.

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