0

I am using rowaction with type as 'action' in lwc datatable. Clicking on which should redirect to external site. First I tried using window.open in the handlerowaction method as below

handleRowAction(event){
    const actionName = event.detail.action.name;
    const row = event.detail.row;
    this.record = row;
    console.log('new value '+this.record.new_value);
    window.open(this.record.new_value);
}

this.record.new_value logs correctly such as - www.google.com in the console log. However, in the UI when I click on rowaction , it redirects to as - InstanceURL/lightning/r/case/{caseId}/view/www.google.com which is nothing but the current page url (Salesforce UI) + external site url . Not sure what I am missing here.

Secondly, I tried using import { NavigationMixin } from 'lightning/navigation'; and the handlerowaction method as below

handleRowAction(event){
    const actionName = event.detail.action.name;
    const row = event.detail.row;
    this.record = row;
    console.log('new value '+this.record.new_value);
    this[NavigationMixin.Navigate]({
    type: 'standard__webPage',
    attributes: {
        url: this.record.new_value
    }
},
true // Replaces the current page in your browser history with the URL

); }

In this case it throws error at the UI level with message pop up as - This page has an error. You might just need to refresh it. First, would you give us some details? (We're reporting this as error ID: -2015273290)

Any idea what could be wrong? An alternative way to redirect external to Salesforce?

1

When using just www.google.com, you're asking for a relative file path. Instead, specify either //www.google.com/ (the server www.google.com using the current protocol, typically https) or https://www.google.com/ (the server www.google.com using the https protocol). The latter is the preferred form.

Relative

some-file.name

Absolute (Same Server)

/path/some-file.name

Absolute (Any Server, Same Protocol)

//server/path/some-file.name

Canonical (Any Server, Any Protocol

https://server/path/some-file.name
| improve this answer | |

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.