Skip to main content
added 89 characters in body
Source Link

enter image description here

enter image description here

Source Link

Prepopulating custom field look up value on Opportunity Using URL hacking

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:selectList> 
                    </apex:pageBlockSectionItem>
                 </apex:pageBlocksection>
          
                <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:pageBlockSectionItem>
                    </apex:pageBlocksection>
                 </apex:pageBlockButtons>   
               </apex:pageBlock>
        </apex:form>
    </apex:page>

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() 
        {   
            System.debug('@@@'+selectedRecordType);
            
            if((selectedRecordType =='PM-P Opportunity' || selectedRecordType =='FPD PR Opportunity' || selectedRecordType =='IR3535 EU' ||selectedRecordType )
            {
            
           Id devRecordTypeId = Schema.getGlobalDescribe().get('Opportunity').getDescribe().getRecordTypeInfosByName().get(selectedRecordType).getRecordTypeId(); 
             
                if(accid!=Null)
                {
                PageReference pageRef=new PageReference('/006/e?retURL=%2F006%2Fo&accid='+accid+'&RecordType='+devRecordTypeId+'&ent=Opportunity&Master_Account__c='+accid+'&RecordType='+devRecordTypeId+'&ent=Opportunity');
                pageRef.getParameters().put('nooverride','1');
                pageRef.setRedirect(true);
                return pageRef;
                }
}

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