0

I am stuck, when I use my lightning component in visualforce page it work fine until i am not using prefix name in visualforce page. When i use prefix name then it will show error"Something has gone wrong. Action failed: PZ33$SelectOptionsForAddress$controller$onGroup [TypeError: Cannot read property 'location' of undefined] Failing descriptor: {PZ3$SelectOptionsForAddress$controller$onGroup}. Please try again."

Visulaforce page:-

<apex:page standardController="Contact" sidebar="true" showHeader="true" standardStylesheets="false" >
 <apex:includeScript value="{!URLFOR($Resource.az3__LatestJquery, '/LatestJQuery/jquery-2.2.3.min.js')}"/>      
 <apex:includeLightning />
<div id="Con" />
 <script>
    var ContactId = "{!$CurrentPage.parameters.id}";
    console.log('::::'+ContactId);
        $Lightning.use("PZ3:AConfigurationApp", function() {
                $Lightning.createComponent(
                    "PZ3:SelectOptionsForAddress",
                    { "ContactId" : ContactId },
                    "Con",
                    function(cmp) {
                        console.log("Component created!");
                        console.log(cmp);
                    });                        
                });
</script>
</apex:page>

Lightning component :-

<aura:component access="GLOBAL">
    <ltng:require styles="/resource/PZ__Bootstrap ,/resource/PZ3__ExternalCssForComponent" scripts='/resource/PZ3__NewRequiredJs' />
    <aura:attribute name="ContactId" type="String" default="" access="GLOBAL"/>
    <aura:attribute name="SelectAddress" type="Boolean" default="true" access="GLOBAL"/>

    <div class="body_container" >
        <div class="col-sm-12 col-lg-6 col-md-8 col-xs-12 panel panel-primary panel-primary2 selectoption-page">
            <div class="panel-heading">Which address you want to validate</div>
            <div class=" panel-body panel_body_details">
                <div class="form-horizontal information-box col-xs-12" >     
                    <div class="form-group">
                        <label class="col-sm-6 col-xs-7 control-label">Only validate mailing address </label>
                        <div class="col-sm-6">
                            <ui:inputRadio aura:id="OnlyM" class="line"
                                      change="{!c.onGroup}" value="{v.value}"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-6 col-xs-7 control-label">Only validate other address </label>
                        <div class="col-sm-6">
                            <ui:inputRadio aura:id="OnlyO" class="line"
                                      change="{!c.onGroup}" value="{v.value}"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-6 col-xs-7 control-label">Validate both mailing address and other address. </label>
                        <div class="col-sm-6">
                            <ui:inputRadio aura:id="BothMO" class="line"
                                      change="{!c.onGroup}" value="{v.value}"/>
                        </div>
                    </div> 
                </div>
            </div>
        </div>
    </div>
</aura:component>

Js:-

({
onGroup : function(component, event, helper) {

    var IsMailingAddress =component.find("OnlyM").get("v.value");
    var IsOtherAddress =component.find("OnlyO").get("v.value");
    var IsBothAddress =component.find("BothMO").get("v.value");
    if(IsMailingAddress){
        var rID = component.get("v.ContactId");           
            window.parent.location.href ='/apex/UpdateContactVF?id='+rID

    }
    else if(IsOtherAddress){
        var rID = component.get("v.ContactId");
        window.parent.location.href ='/apex/ContactForOtherAddressVF?id='+rID

    }else{
        var rID = component.get("v.ContactId");
        window.parent.location.href ='/apex/UpdateContactVF?id='+rID+'&SelectAddress=true'
    }
},})

Please help me to out of this problem. Thanks

2

Lightning uses the Locker Service, which provides a secure DOM. You are not allowed to just use window.parent. Instead, you need to use force:navigateToURL instead, or you should be able to use window.location.

2
  • Thanks for the reply, when i load this visualforce page i get two error msg one is "Uncaught TypeError: jQuery is not a function throws at /resource/az3__NewRequiredJs:3:1" . – Piyush Kumar Jul 23 '16 at 10:41
  • it work for this error "Something has gone wrong. Action failed: PZ33$SelectOptionsForAddress$controller$onGroup [TypeError: Cannot read property 'location' of undefined] Failing descriptor: {PZ3$SelectOptionsForAddress$controller$onGroup}. Please try again." – Piyush Kumar Jul 23 '16 at 12:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.