Skip to main content
How to pre-populate the shipping address on the Opportunity from the Account?

As soon as the user clicks on New Opportunity, the shipping address from Account should pre-populate on the Opportunity Shipping address and this should be editable before saving. 
4 respuestas
  1. 29 sept 2015, 06:57
    Hi Praneeth ,

    There are two ways of solving this problem..

    1) If you are not using any vf page and you want to show shipping address of account in the field of opportuntiy then using workflow rule you can insert account shipping address field value into the opportunity shipping address field.

    Workflow is:

    1 a) Create a workflow with the rule criteria "created, and any time it’s edited to subsequently meet criteria" and write the "Account.Name != null" in the formula evaluates to true.

    1 b) Add field update action on the field of the Opportunity Shipping Address "Account.ShippingStreet".

    2) Second option is that create a vf page and the code of the vf page is:

    <apex:page standardController="Opportunity">

    <script type="text/javascript">

            var __sfdcSessionId = '{!GETSESSIONID()}';

    </script>

        <script src="/soap/ajax/28.0/connection.js" type="text/javascript"></script>

        <script src="/soap/ajax/28.0/apex.js" type="text/javascript"></script>

    <script type="text/javascript">

        function ShippingAdd(){

            var accountidnew = document.getElementById('{!$Component.theForm.thePageBlock.thePageBlockSection.accid}_lkid');

            var query = sforce.connection.query("SELECT ID,Name,ShippingStreet,ShippingState,ShippingPostalCode,ShippingCountry,ShippingCity FROM Account where id='"+accountidnew.value+"'");

            var records = query.getArray('records'); 

                document.getElementById('{!$Component.theForm.thePageBlock.ShippingAddress.ShippingStreet}').value= records[0].ShippingStreet ;

                document.getElementById('{!$Component.theForm.thePageBlock.ShippingAddress.ShippingCity}').value= records[0].ShippingCity ;

                document.getElementById('{!$Component.theForm.thePageBlock.ShippingAddress.ShippingState}').value= records[0].ShippingState ;

                document.getElementById('{!$Component.theForm.thePageBlock.ShippingAddress.ShippingPostalCode}').value= records[0].ShippingPostalCode ;

                document.getElementById('{!$Component.theForm.thePageBlock.ShippingAddress.ShippingCountry}').value= records[0].ShippingCountry ;}

    </script >

    <!--<apex:messages id="msgs" style="font-size:20px; color:red"/> 

    <apex:pageMessage summary="Record not found" severity="info" rendered="{!msg}" strength="3" />-->

            

        <apex:form id="theForm">

            <apex:pageBlock title="Opportunity Edit" mode="Edit" id="thePageBlock">

                <apex:pageBlockButtons >

                    <apex:commandButton id="uploadfile" value="Save" action="{!save}"/>

                    <apex:commandButton value="Cancel" action="{!Cancel}" immediate="true" />

                </apex:pageBlockButtons>           

                <apex:pageBlockSection columns="2" id="thePageBlockSection">

                    <apex:inputField id="accid" value="{!Opportunity.Accountid}"/>                

                </apex:pageBlockSection>            

               <apex:pageBlockSection title="Shipping Address" id="ShippingAddress">

                    <apex:inputCheckbox value="{!Opportunity.Copy_from_Account_Shipping_Address__c}" id="ShippingAddressCheckbox" onclick="ShippingAdd();"/>

                    <apex:inputField value="{!Opportunity.Shipping_Street__c}" id="ShippingStreet"/>

                    <apex:inputField value="{!Opportunity.Shipping_City__c}" id="ShippingCity"/>

                    <apex:inputField value="{!Opportunity.Shipping_State__c}" id="ShippingState"/>

                    <apex:inputField value="{!Opportunity.Shipping_Postal_Code__c}" id="ShippingPostalCode"/>

                    <apex:inputField value="{!Opportunity.Shipping_Country__c}" id="ShippingCountry"/>

                </apex:pageBlockSection>

              </apex:pageBlock>

        </apex:form>

    </apex:page>

     
0/9000