Skip to main content

Salesforce lightning component e.force:navigateToURL


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();
    }
})

Comments

  1. 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
    Most recommended and appreciable app by Salesforce MVP

    ReplyDelete
  2. Good Post. I like your blog. Thanks for Sharing
    Digitally sign your documents instead of doing it manually with the help of DocuSign Integration with Salesforce using API's

    ReplyDelete

Post a Comment

Popular posts from this blog

Best practices for Data Loading in Salesforce

Data loading is a very common requirement in most of the salesforce projects. We need to load many master data and transactional data in production based on requirements that include thousands of records. In this article, I am going to list some best practices that we can follow and keep in mind while loading data in production. 1.     Organization-Wide Sharing defaults - While loading data in production, if objects have ‘Private’ OWD then it does additional processing in the background. Therefore, it is better to load data using read/write OWD and change it to ‘private’ after cutover. 2.     Workflow rules, validation rules, and triggers - If these tools are enabled in your production org while loading data, it can give many errors and it may slow down the process. Therefore, it is recommended to disable these tools before loading data.   3.     Bulk API Vs. SOAP API - SOAP API is useful for small data sets where...

How to start with salesforce

'Salesforce' is cloud computing company, which provides many services and uses many technology to deliver services. Salesforce is high demanding cloud computing technology that provides 'PAAS' to create your application on cloud and deliver to users.  But how to start with salesforce. This article will provide you basic idea to start with Salesforce if you are new to this technology.  If you are a developer, it will be very easy to jump in Salesforce technology and master it. How Salesforce is useful to deliver solution: Salesforce platform will help you to deliver CRM Applications. You can build CRM applications which can be used by businesses to track sales activity. Salesforce Platform is employed across all industries to build and launch game changing apps for every department in a company, including HR, IT, operations, finance, legal, and marketing.  Here is the example of some applications that you can build with help of salesforce. ...