function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
John Manager Training DepJohn Manager Training Dep 

How to populate "ShippingAddress" same as 'BillingAddress' for Account object based on checkbox?

Hi Team,

In lightning "Account" object i want to create a checkbox field IsSameAsBillingAddress?.

If the checkbox is selected then "ShippingAddress" should be populated as 'BillingAddress'.
If unchecked then the "ShippingAddress" should be blank.

Out of current process builder and flow builder which one is an efficient way to do it?

Many Thanks in advance!
Vikash GoyalVikash Goyal
Hi John,

Other than process builder, you can create workflow rules for this. You have to create 2 workflow rules for this :

1. To copy BillingAddress in ShippingAddress :
  • Workflow Rule :
         User-added image

          Field Updates:  Total 5 field updates will be there, one for each shipping field (ShippingCity, ShippingCountry, ShippingState, ShippingStreet, ShippingPostalCode), Similar to the following one (It's for ShippingCountry) :
          User-added image

1. To update ShippingAddress with blank value:
  • Workflow Rule :
         User-added image

          Field Updates:  Total 5 field updates will be there, one for each shipping field (ShippingCity, ShippingCountry, ShippingState, ShippingStreet, ShippingPostalCode), Similar to the following one (It's for ShippingCountry) :
          User-added image

Hope this will help you.

Thanks
 
Deepali KulshresthaDeepali Kulshrestha
Hi John,

You can try this code it is working according to your condition.

Component
 
<aura:component implements="lightning:isUrlAddressable,force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
    
    <aura:attribute name="PageHeading" type="String" default="Copy Account Address Through Check Box"/>
    <aura:attribute name="RegForm" type="Account" default="{'sobjectType' : 'Account'}"/>
    <aura:attribute name="CheckboxValue" type="Boolean" default="false"/>
    
    <div class="slds-m-top--xx-large">
        <div class="slds-page-header">
            <div class="slds-align--absolute-center">
                <div class="slds-text-heading--large">       
                    {!v.PageHeading}
                </div>
            </div>
        </div>
    </div>
    <br/> <br/>
    
    <div class = "slds-size--3-of-8">
        <div class="slds-section slds-is-open">
            <h3 class="slds-section__title slds-theme_shade">
                <span class="slds-truncate slds-p-horizontal_small" title="Section Title">Billing Address</span>
            </h3>
            <br/>
            <div aria-hidden="false" class="slds-section__content">
                <lightning:input label="Billing Street " name="BillingStreet" value="{!v.RegForm.BillingStreet}"/>
                <br/>
                <lightning:input label="Billing City" name="BillingCity" value="{!v.RegForm.BillingCity}"/>
                <br/>
                <lightning:input label="Billing State" name="BillingState" value="{!v.RegForm.BillingState}"/>
                <br/>
                <lightning:input label="Billing Country" name="BillingCountry" value="{!v.RegForm.BillingCountry}"/>
                <br/>
                <lightning:input type="checkbox" aura:id="checkBoxId" label="Is Shipping address same as Billing address" name="checkbox" onchange="{!c.onClickCheckBox}"/>
                <br/>
            </div>
        </div>
        <br/> 
        <div class="slds-section slds-is-open">
            <h3 class="slds-section__title slds-theme_shade">
                <span class="slds-truncate slds-p-horizontal_small" title="Section Title">Shipping Address</span>
            </h3>
            <br/>
            <div aria-hidden="false" class="slds-section__content">
                <lightning:input label="Shipping Street " name="ShippingStreet" value="{!v.RegForm.ShippingStreet}"/>
                <br/>
                <lightning:input label="Shipping City" name="ShippingCity" value="{!v.RegForm.ShippingCity}"/>
                <br/>
                <lightning:input label="Shipping State" name="ShippingState" value="{!v.RegForm.ShippingState}"/>
                <br/>
                <lightning:input label="Shipping Country" name="ShippingCountry" value="{!v.RegForm.ShippingCountry}"/>
            </div>
        </div>
    </div>
</aura:component>

Controller

({
    onClickCheckBox : function(component, event, helper) {
        var checkBoxV = component.find("checkBoxId").get("v.checked");
        component.set("v.CheckboxValue", checkBoxV);
        var cb = component.get("v.CheckboxValue");
        
        var streetStr=component.get("v.RegForm.BillingStreet");
        var cityStr=component.get("v.RegForm.BillingCity");
        var stateStr=component.get("v.RegForm.BillingState");
        var countryStr=component.get("v.RegForm.BillingCountry");
        
        if(cb==true) {
            component.set("v.RegForm.ShippingStreet",streetStr);
            component.set("v.RegForm.ShippingCity",cityStr);
            component.set("v.RegForm.ShippingState",stateStr);
            component.set("v.RegForm.ShippingCountry",countryStr);
        }
        else{
            component.set("v.RegForm.ShippingStreet","");
            component.set("v.RegForm.ShippingCity","");
            component.set("v.RegForm.ShippingState","");
            component.set("v.RegForm.ShippingCountry","");
        }
    }
})
I suggest to visit this link, it will help you 

https://developer.salesforce.com/forums?id=9062I000000IJeEQAW

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha.