1

I have a LWC code where if you click the button it generates a URL and then opens it. I have another aura component that is launched from a flow and it does the exact same thing as the LWC but this actually works and the LWC is not working. I was wondering if anyone could help me on how to rewrite the aura controller code as a LWC JS code? Here is the working aura code:

Component:
    <aura:component implements="force:lightningQuickAction,lightning:availableForFlowActions">
        <aura:attribute name="URLpassing" type="String"/>
    </aura:component>

JS cONTROLLER:
    ({    
        invoke : function(component, event, helper) 
            var URL = component.get("v.URLpassing");
            var redirect = $A.get("e.force:navigateToURL");
       
            // Pass the record ID to the event
            redirect.setParams({
                "url": URL,
            });
            
            // Open the record
            redirect.fire();
        }
    })

The url is passed from a flow to this aura component

I want to replicate the controller code into my LWC JS so it behaves the same way. This is what my Lwc is doing: HTML:

<template>
<div>
            <lightning-button class="aButton" label="URLCreator" onclick={UrlCreator}></lightning-button>
        </div>
</template>

JS:
export default class URLCreate extends NavigationMixin(LightningElement) {
    @api recordId;
    @api accId;
    @track PageUrl;
URLCreator(event) {
        
        this.PageUrl = '/apex/AVFpage_HTML';
        this.PageUrl += "&accountId="+ this.accId;
        
        
        this[NavigationMixin.GenerateUrl]({
            type: 'standard__webPage',
            attributes: {
                url: this.PageUrl
            }
        }).then(generatedUrl => { //this set of code I dont think is working. I need to replicate this like my aura controller code
            
            sforce.one.navigateToUrl(generatedUrl); 
        });
    }

If anymore can help, that would create. Again, since my aura is working, I would like to mimic the functionality/code into my LWC but I dont know how to write that aura functionality as LWC Thank you

1 Answer 1

1

You can use window.open method once the URL is generated and the promise is resolved, to navigate using the NavigationMixin.

Try the below code

//Navigate to pdf page
UrlCreator() {
    this.PageUrl = '/apex/AVFpage_HTML';
    this.PageUrl += "&accountId="+ this.accId;
    this[NavigationMixin.GenerateUrl]({
        type: 'standard__webPage',
        attributes: {
            url: this.PageUrl
        }
    }).then(generatedUrl => {
        window.open(generatedUrl);
    });
}
3
  • Thats what I had originally had but that does not open in Android or mobile apps Nov 10, 2020 at 0:11
  • I suggest you add this info in the question that it does not work for a specific device. Is your android app native, hybrid, or Salesforce 1 app? Nov 10, 2020 at 0:15
  • srivastava it is on a Android device using SF 1 mobile app Nov 10, 2020 at 14:35

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.