0

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");
        action.setParams({
            "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');
            }
        });

        $A.enqueueAction(action);

    }

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?

1
  • 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

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';
            this.gotoURL(URL);
        }

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

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .