As in the accounts edit page, I want to achieve the Copy Billing address to shipping address for a custom object. I know this can be done either WF or trigger but I want that to be dynamic and based on user interaction. So I thought of using hyperlink. I have no idea of how to get that using hyperlink. Can anybody help me? or any other solution please?
To make the logic run in the browser you need to use JavaScript. We have a page that does this without using jQuery; there may be more elegant ways to accomplish the same thing but this works. Replace the Account field references with your custom object field references.
Here are the relevant parts
<apex:inputField id="b0" value="{!account.BillingStreet}"/>
<apex:inputField id="b1" value="{!account.BillingCity}"/>
<apex:inputField id="b2" value="{!account.BillingState}"/>
<apex:inputField id="b3" value="{!account.BillingPostalCode}"/>
<apex:inputField id="b4" value="{!account.BillingCountry}"/>
<apex:outputLink value="javascript: addressCopy('{!$Component.b0}', '{!$Component.b1}', '{!$Component.b2}', '{!$Component.b3}', '{!$Component.b4}', '{!$Component.s0}', '{!$Component.s1}', '{!$Component.s2}', '{!$Component.s3}', '{!$Component.s4}')">Copy Billing Address to Shipping Address</apex:outputLink>
<apex:inputField id="s0" value="{!account.ShippingStreet}"/>
<apex:inputField id="s1" value="{!account.ShippingCity}"/>
<apex:inputField id="s2" value="{!account.ShippingState}"/>
<apex:inputField id="s3" value="{!account.ShippingPostalCode}"/>
<apex:inputField id="s4" value="{!account.ShippingCountry}"/>
<script type="text/javascript">
function addressCopy(b0, b1, b2, b3, b4, s0, s1, s2, s3, s4) {
// Copy billing fields to shipping fields
document.getElementById(s0).value = document.getElementById(b0).value;
document.getElementById(s1).value = document.getElementById(b1).value;
document.getElementById(s2).value = document.getElementById(b2).value;
document.getElementById(s3).value = document.getElementById(b3).value;
document.getElementById(s4).value = document.getElementById(b4).value;
// No form submission
return false;
}
</script>
-
-
with the standard page layout of custom object, using hyperlink is this functionality possible? @Keith C – ləːnə Apr 23 '14 at 9:33
-
@ləːnə apex:outputLink does produce a HTML hyperlink. Using standard layouts you can add a JavaScript link but that doesn't appear in the edit view; also I don't know how you would get the right field ids. You should probably ask a separate question on this. – Keith C Apr 23 '14 at 9:38