JS Controller

onconfirm : function(component, event) {
        var windowHref = window.location.href;
        var url = new URL(windowHref);
        var recordId = url.searchParams.get("c__recordId");

        var recordtype = component.get("v.selectedRecordType");
        console.log('recordType : ' + recordtype);
        console.log('parameter : ' + recordId);
        var action = component.get("c.CreateNewCon");
            "recType" : recordtype 
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                console.log("This is Success");
                // I'd like to move from here to url.
            } else {
                console.log('This is Error');



I want to process the following code successfully in apex controller and go to the URL when the status is SUCCESS. What should I do?

  • to what URL you would like to navigate? is it a salesforce URL, for the record, report, etc, or it is an external URL? Aug 11, 2021 at 7:32

1 Answer 1


You can use any of the following event based on where you want to navigate.

  • force:navigateToSObject
  • force:navigateToRelatedList
  • force:navigateToSObject
  • force:navigateToURL
  • force:navigateToObjectHome

E.g you want to navigate to certain URL then use force:navigateToURL event.

Add gotoURLfunction to your component and Inside if condition use it.

    if (state === "SUCCESS") {
            const URL = 'your url here';

gotoURL : function (url) {
    var urlEvent = $A.get("e.force:navigateToURL");
      "url": url

Refer component library for more information - https://developer.salesforce.com/docs/component-library/bundle/force:navigateToURL/documentation

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.