This article will explain how to use ‘e.force:navigateToURL’
lightning component to navigate the system to any URL (visualforce page,
record, any custom URL).
Syntax of ‘e.force:navigateToURL’
var urlEvent = $A.get("e.force:navigateToURL");
urlEvent.setParams({
"url":
"/" + recordId ,
"isredirect":
"true"
});
urlEvent.fire();
Description of the parameters,
1.
URl – Set this parameter to the required URL that
you want to redirect, in this example ‘recordId’ is my variable with has the Id
of the record I want to redirect. We can use static URL (e.g https://www.salesforce.com ) as well.
2.
Isredirect – This is optional, this flag will
not create 2 history entries for hybrid.
3.
Fire() – This will redirect the system to the
specified URL
Example
RedirectToAcc.cmp
<aura:component
implements="flexipage:availableForRecordHome,force:hasRecordId"
access="global" >
<lightning:button label="Go To Account" onclick="{!c.redirect}"/>
</aura:component>
RedirectToAccController.js
({
redirect : function(component, event, helper) {
helper.redirect(component,
event, helper);
})
RedirectToAccHelper.js
({
redirect
: function(component, event, helper) {
var urlEvent =
$A.get("e.force:navigateToURL");
urlEvent.setParams({
"url": "https://www.salesforce.com" ,
"isredirect": "true"
});
urlEvent.fire();
}
})

Anyone looking for Salesforce app which save their time and can perform bulk CRUD operations in few click - their search end at Salesforce Appexchange app Bulk Object Field Creator
ReplyDeleteMost recommended and appreciable app by Salesforce MVP
Good Post. I like your blog. Thanks for Sharing
ReplyDeleteDigitally sign your documents instead of doing it manually with the help of DocuSign Integration with Salesforce using API's