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
mhittmhitt 

lightning component parsing error

Hi friends,

I am trying to build a lightning component that launches a flow to create a new Order record, and then redirects the user to that new Order when they click finish.  Since I am new at writing components I copied the code from here, but when I save I am getting this parsing error 
Failed to save LaunchOpenOrderController.js: ESLINT_ERROR: {c:LaunchOpenOrder - CONTROLLER} line:col [7:39] --> Parsing error: Unexpected token ( : Source

Here is my component
<aura:component implements="force:lightningQuickAction,forceCommunity:availableForAllPageTypes" access="global">
    <aura:handler name="init" value="{!this}" action="{!c.init}" />
    <lightning:flow aura:id="flowData" onstatuschange="{!c.handleStatusChange}"/>
</aura:component>


And the controller 
({
    init : function (component) {
        // Find the component whose aura:id is "flowData"
        var flow = component.find("flowData");
        // In that component, start your flow. Reference the flow's Unique Name.
        flow.startFlow("OpenOrderPOC");
        handleStatusChange : function (component, event) {
            if(event.getParam("status") === "FINISHED") {
                var outputVariables = event.getParam("outputVariables");
                var outputVar;
                for(var i = 0; i < outputVariables.length; i++) {
                    outputVar = outputVariables[i];
                    if(outputVar.name === "redirect") {
                        var urlEvent = $A.get("e.force:navigateToSObject");
                        urlEvent.setParams({
                            "recordId": outputVar.value,
                            "isredirect": "true"
                        });
                        urlEvent.fire();
                    }
                }
            }
        }
    }
})

Could I please have some help? :)
Thank you!
Best Answer chosen by mhitt
Raj VakatiRaj Vakati
Try this

https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/components_using_flow_inputs_get.htm
({
    init : function (component) {
        // Find the component whose aura:id is "flowData"
        var flow = component.find("flowData");
        // In that component, start your flow. Reference the flow's Unique Name.
        flow.startFlow("OpenOrderPOC");
    },
    
    handleStatusChange : function (component, event) {
        if(event.getParam("status") === "FINISHED") {
            var outputVariables = event.getParam("outputVariables");
            var outputVar;
            for(var i = 0; i < outputVariables.length; i++) {
                outputVar = outputVariables[i];
                if(outputVar.name === "redirect") {
                    var urlEvent = $A.get("e.force:navigateToSObject");
                    urlEvent.setParams({
                        "recordId": outputVar.value,
                        "isredirect": "true"
                    });
                    urlEvent.fire();
                }
            }
        }
    }
    
})

 

All Answers

Raj VakatiRaj Vakati
Try this

https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/components_using_flow_inputs_get.htm
({
    init : function (component) {
        // Find the component whose aura:id is "flowData"
        var flow = component.find("flowData");
        // In that component, start your flow. Reference the flow's Unique Name.
        flow.startFlow("OpenOrderPOC");
    },
    
    handleStatusChange : function (component, event) {
        if(event.getParam("status") === "FINISHED") {
            var outputVariables = event.getParam("outputVariables");
            var outputVar;
            for(var i = 0; i < outputVariables.length; i++) {
                outputVar = outputVariables[i];
                if(outputVar.name === "redirect") {
                    var urlEvent = $A.get("e.force:navigateToSObject");
                    urlEvent.setParams({
                        "recordId": outputVar.value,
                        "isredirect": "true"
                    });
                    urlEvent.fire();
                }
            }
        }
    }
    
})

 
This was selected as the best answer
Raj VakatiRaj Vakati
handleStatusChange is another function ..
mhittmhitt
Thank you Raj! This seems to work (I can save without errors). Time to test the component.
mhittmhitt
@Raj, so now when I finish the flow it does not redirect me to the newly created order. I created another component a while back that uses a "window.open" tag to navigate user to another web page. Is there something like this missing from my code?
Raj VakatiRaj Vakati
Can you add some console.log and see where it is breaking ?
mhittmhitt
I haven't seen this yet, where would I include it in the code, and should anything be inside the () like system.debug()?