function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
GMASJGMASJ 

urlEvent.fire()

Hi, 

  Below controller is working as expected but when user tries to open for first time its not working when user clicks for second time only then it starts working. 

I see the issue is because urlEvent.fire() is inside the condition. 

if(erpId != 'nullPPP') { urlEvent.fire(); }

Please suggest me how to fix the first time issue is there an alternative way to approch this isuse. 
({
	doInit : function(component, event, helper) {

        console.log("doInit == Start " );
        var action = component.get("c.getAccessKey");
        action.setParams({
            recordId: component.get("v.recordId")
        });
        action.setCallback(this, function(data) {
            console.log('Return Value _____________' + data.getReturnValue());
            component.set("v.key", data.getReturnValue());
            
             console.log("handleRecordUpdated == Start " );

		var urlEvent = $A.get("e.force:navigateToURL");
        console.log(component.get("v.key") );
        var url = 'https://salesportal.fortinet.com/potracker/login?moduleName=trackingService&accessKey=' +  data.getReturnValue();

        console.log(url);
        urlEvent.setParams({
            "url": url
        });
        var erpId = component.get("v.act.Oracle_ERP_ID__c") + 'PPP';
        console.log(erpId + '___erpd_id ' + ( erpId  != 'nullPPP'));
        if(erpId != 'nullPPP') {
	        urlEvent.fire();
        }
        console.log("doInit == innnEnd");
            
        });
        $A.enqueueAction(action);
                
        console.log("doInit == End");
    },
    handleRecordUpdated: function(component, event, helper) {
        console.log("handleRecordUpdated == Start " );
        var eventParams = event.getParams();
         console.log("eventParams.type == " + eventParams.changeType);
        if(eventParams.changeType === "LOADED") {
           // record is loaded (render other component which needs record data value)
            console.log("Record is loaded successfully. == " + eventParams.changeType);
            console.log("doInit == innnnnStart " );

		var urlEvent = $A.get("e.force:navigateToURL");
        console.log(component.get("v.key") );
        var url = 'https://apptest.fortinet.com/potracker/login?moduleName=trackingService&accessKey=' + component.get("v.key");

        console.log(url);
        urlEvent.setParams({
            "url": url
        });
        //urlEvent.fire();
        console.log("doInit == innnEnd");
            
        } else if(eventParams.changeType === "CHANGED") {
            // record is changed
        } else if(eventParams.changeType === "REMOVED") {
            // record is deleted
        } else if(eventParams.changeType === "ERROR") {
            // there’s an error while loading, saving, or deleting the record
        }
        console.log("handleRecordUpdated == End");
    }		
})
Thanks