You need to sign in to do that
Don't have an account?
Praneeth P
How to Pre-populate Shipping Address on Opportunity from Account
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.
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.
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>
All Answers
If you want like this then you can override new opportunity button with your vf page and custom controller .
Second thing you can populate from trigger before insert which will not populate in standard layout ,and while editing that record you can allow user to edit the address .
Let me know if it helps!!
Thanks
Mnaoj
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>
I tried your code regarding this issue as I am also facing same issue , I was not able to display the shipping details from the account object.
Please let me know you can reach me here kulkarnipriyava@gmail.com regarding the issue.
I need help thanks
Priya
I tried your code, But its displaying blank when I use it in pagelayout , Any ideas?
Thanks
Priya